workdash 0.1.0__tar.gz → 0.2.0__tar.gz
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-0.1.0 → workdash-0.2.0}/PKG-INFO +27 -10
- {workdash-0.1.0 → workdash-0.2.0}/README.md +26 -9
- {workdash-0.1.0 → workdash-0.2.0}/pyproject.toml +1 -1
- workdash-0.2.0/src/workdash/config.py +450 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/launcher.py +35 -9
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/workdash.py +38 -12
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash.egg-info/PKG-INFO +27 -10
- workdash-0.2.0/tests/test_config.py +535 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_launcher.py +14 -4
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_workdash.py +56 -5
- workdash-0.1.0/src/workdash/config.py +0 -207
- workdash-0.1.0/tests/test_config.py +0 -259
- {workdash-0.1.0 → workdash-0.2.0}/LICENSE +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/setup.cfg +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/__init__.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/__main__.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/analysis_cache.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/analyzer.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/backend.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/github_client.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/included_items.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/models.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/prompts/__init__.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/prompts/analyze_issue.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/prompts/analyze_pr.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/prompts/launch_issue.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/prompts/launch_pr.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/prompts/launch_review.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/repo_resolver.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/repo_worktree.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash/tui.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash.egg-info/SOURCES.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash.egg-info/dependency_links.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash.egg-info/entry_points.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash.egg-info/requires.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/src/workdash.egg-info/top_level.txt +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_analysis_cache.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_analyzer.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_backend.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_github_client.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_included_items.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_normalization.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_repo_resolver.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_repo_worktree.py +0 -0
- {workdash-0.1.0 → workdash-0.2.0}/tests/test_tui.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: workdash
|
|
3
|
-
Version: 0.
|
|
3
|
+
Version: 0.2.0
|
|
4
4
|
Summary: Text-based GitHub work triage dashboard.
|
|
5
5
|
Author-email: Alessandro Molina <alessandro@molina.fyi>
|
|
6
6
|
License: GNU GENERAL PUBLIC LICENSE
|
|
@@ -724,16 +724,23 @@ been tested on Windows.
|
|
|
724
724
|
## Requirements
|
|
725
725
|
|
|
726
726
|
- Python `>=3.12`.
|
|
727
|
-
- [`gh`](https://cli.github.com/)
|
|
728
|
-
|
|
729
|
-
|
|
730
|
-
|
|
731
|
-
|
|
727
|
+
- [`gh`](https://cli.github.com/) authenticated (`gh auth status` must
|
|
728
|
+
succeed). The `workdash --configure` wizard detects a `gh` binary on `PATH`;
|
|
729
|
+
when none is available, it installs a local copy under
|
|
730
|
+
`~/.config/workdash/` from <https://github.com/cli/cli/releases/latest>.
|
|
731
|
+
The authenticated account should have access to the repositories you want to
|
|
732
|
+
track; if GitHub requires additional repository authorization for a repository
|
|
733
|
+
while loading a specific work source, `workdash` warns, skips that inaccessible
|
|
734
|
+
repository or item, and still loads the others.
|
|
732
735
|
- `xdg-open` or `open` for opening links and rendered analyses in your browser.
|
|
733
736
|
- `zellij` for the interactive dashboard, terminal panes, and agent sessions.
|
|
734
|
-
|
|
735
|
-
|
|
736
|
-
|
|
737
|
+
The `workdash --configure` wizard detects a `zellij` binary on `PATH`; when
|
|
738
|
+
none is available, it can install a local copy under `~/.config/workdash/`.
|
|
739
|
+
When `workdash` starts outside Zellij, it prefers your global `zellij` when
|
|
740
|
+
one is available, otherwise uses the local configured copy, starts a fresh
|
|
741
|
+
`workdash-<random>` session, and runs the dashboard inside it.
|
|
742
|
+
- On every startup, `workdash` prefers your global GitHub CLI when one is
|
|
743
|
+
available, otherwise uses the local configured copy.
|
|
737
744
|
- Optional, depending on which actions you use from the TUI:
|
|
738
745
|
- `claude` — to analyze or launch a Claude coding session.
|
|
739
746
|
- `codex` — to analyze or launch a ChatGPT Codex session.
|
|
@@ -766,13 +773,23 @@ workdash --configure
|
|
|
766
773
|
The wizard fills in:
|
|
767
774
|
|
|
768
775
|
- Your GitHub username.
|
|
776
|
+
- Zellij availability. If `zellij` is not on `PATH`, the wizard downloads the
|
|
777
|
+
latest release binary into the workdash configuration directory.
|
|
778
|
+
- GitHub CLI availability. If `gh` is not on `PATH`, the wizard downloads the
|
|
779
|
+
latest release binary into the workdash configuration directory. Authentication
|
|
780
|
+
is still handled by `gh`; run `gh auth login` if startup reports that `gh` is
|
|
781
|
+
not authenticated.
|
|
769
782
|
- The list of repositories to track (see *Repository selectors* below).
|
|
770
783
|
- A working directory where per-item git worktrees will live.
|
|
771
784
|
- The analyze and launch commands for Claude and Codex (auto-detected when the
|
|
772
785
|
tools are on your `PATH`).
|
|
773
786
|
|
|
774
787
|
You can edit `~/.config/workdash/config.json` by hand at any time. Re-running
|
|
775
|
-
`--configure` only prompts for fields that are still empty
|
|
788
|
+
`--configure` only prompts for fields that are still empty, except for Zellij:
|
|
789
|
+
the wizard always checks for a global `zellij` first and downloads a fresh
|
|
790
|
+
local binary when no global binary exists. It does the same for `gh`, checking
|
|
791
|
+
for a global GitHub CLI first and downloading a fresh local copy when none is
|
|
792
|
+
available.
|
|
776
793
|
|
|
777
794
|
## Usage
|
|
778
795
|
|
|
@@ -18,16 +18,23 @@ been tested on Windows.
|
|
|
18
18
|
## Requirements
|
|
19
19
|
|
|
20
20
|
- Python `>=3.12`.
|
|
21
|
-
- [`gh`](https://cli.github.com/)
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
21
|
+
- [`gh`](https://cli.github.com/) authenticated (`gh auth status` must
|
|
22
|
+
succeed). The `workdash --configure` wizard detects a `gh` binary on `PATH`;
|
|
23
|
+
when none is available, it installs a local copy under
|
|
24
|
+
`~/.config/workdash/` from <https://github.com/cli/cli/releases/latest>.
|
|
25
|
+
The authenticated account should have access to the repositories you want to
|
|
26
|
+
track; if GitHub requires additional repository authorization for a repository
|
|
27
|
+
while loading a specific work source, `workdash` warns, skips that inaccessible
|
|
28
|
+
repository or item, and still loads the others.
|
|
26
29
|
- `xdg-open` or `open` for opening links and rendered analyses in your browser.
|
|
27
30
|
- `zellij` for the interactive dashboard, terminal panes, and agent sessions.
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
+
The `workdash --configure` wizard detects a `zellij` binary on `PATH`; when
|
|
32
|
+
none is available, it can install a local copy under `~/.config/workdash/`.
|
|
33
|
+
When `workdash` starts outside Zellij, it prefers your global `zellij` when
|
|
34
|
+
one is available, otherwise uses the local configured copy, starts a fresh
|
|
35
|
+
`workdash-<random>` session, and runs the dashboard inside it.
|
|
36
|
+
- On every startup, `workdash` prefers your global GitHub CLI when one is
|
|
37
|
+
available, otherwise uses the local configured copy.
|
|
31
38
|
- Optional, depending on which actions you use from the TUI:
|
|
32
39
|
- `claude` — to analyze or launch a Claude coding session.
|
|
33
40
|
- `codex` — to analyze or launch a ChatGPT Codex session.
|
|
@@ -60,13 +67,23 @@ workdash --configure
|
|
|
60
67
|
The wizard fills in:
|
|
61
68
|
|
|
62
69
|
- Your GitHub username.
|
|
70
|
+
- Zellij availability. If `zellij` is not on `PATH`, the wizard downloads the
|
|
71
|
+
latest release binary into the workdash configuration directory.
|
|
72
|
+
- GitHub CLI availability. If `gh` is not on `PATH`, the wizard downloads the
|
|
73
|
+
latest release binary into the workdash configuration directory. Authentication
|
|
74
|
+
is still handled by `gh`; run `gh auth login` if startup reports that `gh` is
|
|
75
|
+
not authenticated.
|
|
63
76
|
- The list of repositories to track (see *Repository selectors* below).
|
|
64
77
|
- A working directory where per-item git worktrees will live.
|
|
65
78
|
- The analyze and launch commands for Claude and Codex (auto-detected when the
|
|
66
79
|
tools are on your `PATH`).
|
|
67
80
|
|
|
68
81
|
You can edit `~/.config/workdash/config.json` by hand at any time. Re-running
|
|
69
|
-
`--configure` only prompts for fields that are still empty
|
|
82
|
+
`--configure` only prompts for fields that are still empty, except for Zellij:
|
|
83
|
+
the wizard always checks for a global `zellij` first and downloads a fresh
|
|
84
|
+
local binary when no global binary exists. It does the same for `gh`, checking
|
|
85
|
+
for a global GitHub CLI first and downloading a fresh local copy when none is
|
|
86
|
+
available.
|
|
70
87
|
|
|
71
88
|
## Usage
|
|
72
89
|
|
|
@@ -0,0 +1,450 @@
|
|
|
1
|
+
"""Workdash configuration management."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import json
|
|
6
|
+
import platform
|
|
7
|
+
import shutil
|
|
8
|
+
import stat
|
|
9
|
+
import tarfile
|
|
10
|
+
import urllib.request
|
|
11
|
+
import zipfile
|
|
12
|
+
from collections.abc import Callable
|
|
13
|
+
from dataclasses import dataclass, field
|
|
14
|
+
from io import BytesIO
|
|
15
|
+
from pathlib import Path
|
|
16
|
+
|
|
17
|
+
CONFIG_PATH = Path.home() / ".config" / "workdash" / "config.json"
|
|
18
|
+
LOCAL_BIN_PATH = CONFIG_PATH.parent / "bin"
|
|
19
|
+
ZELLIJ_INSTALL_PATH = LOCAL_BIN_PATH / "zellij"
|
|
20
|
+
GH_INSTALL_PATH = LOCAL_BIN_PATH / "gh"
|
|
21
|
+
GH_LATEST_RELEASE_API_URL = "https://api.github.com/repos/cli/cli/releases/latest"
|
|
22
|
+
GH_LATEST_RELEASE_PAGE_URL = "https://github.com/cli/cli/releases/latest"
|
|
23
|
+
|
|
24
|
+
_REQUIRED_FIELDS = ("github_username", "repositories", "workdir")
|
|
25
|
+
_DEFAULT_CLAUDE_ANALYZE = "claude -p"
|
|
26
|
+
_DEFAULT_CLAUDE_LAUNCH = "claude"
|
|
27
|
+
_DEFAULT_CODEX_ANALYZE = "codex exec"
|
|
28
|
+
_DEFAULT_CODEX_LAUNCH = "codex"
|
|
29
|
+
_DEFAULT_WORKDIR = "~/wrk"
|
|
30
|
+
|
|
31
|
+
|
|
32
|
+
@dataclass(frozen=True)
|
|
33
|
+
class AgentConfig:
|
|
34
|
+
"""Per-agent command configuration."""
|
|
35
|
+
|
|
36
|
+
analyze: str = ""
|
|
37
|
+
launch: str = ""
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
@dataclass(frozen=True)
|
|
41
|
+
class WorkdashConfig:
|
|
42
|
+
"""Runtime configuration loaded from ~/.config/workdash/config.json."""
|
|
43
|
+
|
|
44
|
+
github_username: str = ""
|
|
45
|
+
claude: AgentConfig = field(default_factory=AgentConfig)
|
|
46
|
+
codex: AgentConfig = field(default_factory=AgentConfig)
|
|
47
|
+
repositories: tuple[str, ...] = ()
|
|
48
|
+
workdir: str = ""
|
|
49
|
+
|
|
50
|
+
|
|
51
|
+
def _config_to_json(config: WorkdashConfig) -> str:
|
|
52
|
+
return (
|
|
53
|
+
json.dumps(
|
|
54
|
+
{
|
|
55
|
+
"github_username": config.github_username,
|
|
56
|
+
"agents": {
|
|
57
|
+
"claude": {"analyze": config.claude.analyze, "launch": config.claude.launch},
|
|
58
|
+
"codex": {"analyze": config.codex.analyze, "launch": config.codex.launch},
|
|
59
|
+
},
|
|
60
|
+
"repositories": list(config.repositories),
|
|
61
|
+
"workdir": config.workdir,
|
|
62
|
+
},
|
|
63
|
+
indent=2,
|
|
64
|
+
ensure_ascii=True,
|
|
65
|
+
)
|
|
66
|
+
+ "\n"
|
|
67
|
+
)
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
def load_config(path: Path = CONFIG_PATH) -> WorkdashConfig:
|
|
71
|
+
"""Load config from *path*; missing file returns an empty configuration.
|
|
72
|
+
|
|
73
|
+
Raises :class:`RuntimeError` when the file exists but cannot be read or
|
|
74
|
+
parsed, so a corrupted config surfaces an actionable error instead of
|
|
75
|
+
silently reverting to defaults.
|
|
76
|
+
"""
|
|
77
|
+
|
|
78
|
+
if not path.exists():
|
|
79
|
+
return WorkdashConfig()
|
|
80
|
+
try:
|
|
81
|
+
contents = path.read_text(encoding="utf-8")
|
|
82
|
+
except OSError as error:
|
|
83
|
+
raise RuntimeError(f"Failed to read configuration at {path}: {error}") from error
|
|
84
|
+
try:
|
|
85
|
+
raw = json.loads(contents)
|
|
86
|
+
except json.JSONDecodeError as error:
|
|
87
|
+
raise RuntimeError(
|
|
88
|
+
f"Configuration at {path} is not valid JSON: {error.msg} "
|
|
89
|
+
f"(line {error.lineno}, column {error.colno})"
|
|
90
|
+
) from error
|
|
91
|
+
if not isinstance(raw, dict):
|
|
92
|
+
raise RuntimeError(
|
|
93
|
+
f"Configuration at {path} must be a JSON object, got {type(raw).__name__}."
|
|
94
|
+
)
|
|
95
|
+
repositories_raw = raw.get("repositories")
|
|
96
|
+
repositories = tuple(repositories_raw) if isinstance(repositories_raw, list) else ()
|
|
97
|
+
agents_raw = raw.get("agents")
|
|
98
|
+
claude_config = AgentConfig()
|
|
99
|
+
codex_config = AgentConfig()
|
|
100
|
+
if isinstance(agents_raw, dict):
|
|
101
|
+
claude_raw = agents_raw.get("claude")
|
|
102
|
+
if isinstance(claude_raw, dict):
|
|
103
|
+
claude_config = AgentConfig(
|
|
104
|
+
analyze=claude_raw.get("analyze", ""),
|
|
105
|
+
launch=claude_raw.get("launch", ""),
|
|
106
|
+
)
|
|
107
|
+
codex_raw = agents_raw.get("codex")
|
|
108
|
+
if isinstance(codex_raw, dict):
|
|
109
|
+
codex_config = AgentConfig(
|
|
110
|
+
analyze=codex_raw.get("analyze", ""),
|
|
111
|
+
launch=codex_raw.get("launch", ""),
|
|
112
|
+
)
|
|
113
|
+
return WorkdashConfig(
|
|
114
|
+
github_username=raw.get("github_username", ""),
|
|
115
|
+
claude=claude_config,
|
|
116
|
+
codex=codex_config,
|
|
117
|
+
repositories=repositories,
|
|
118
|
+
workdir=raw.get("workdir", "") or raw.get("source_directory", ""),
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
|
|
122
|
+
def save_config(config: WorkdashConfig, path: Path = CONFIG_PATH) -> None:
|
|
123
|
+
"""Write *config* to *path*, creating parent directories as needed."""
|
|
124
|
+
|
|
125
|
+
path.parent.mkdir(parents=True, exist_ok=True)
|
|
126
|
+
path.write_text(_config_to_json(config), encoding="utf-8")
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def validate_config(config: WorkdashConfig) -> list[str]:
|
|
130
|
+
"""Return names of required fields that are empty or missing."""
|
|
131
|
+
|
|
132
|
+
missing: list[str] = []
|
|
133
|
+
if not config.github_username:
|
|
134
|
+
missing.append("github_username")
|
|
135
|
+
if not config.repositories:
|
|
136
|
+
missing.append("repositories")
|
|
137
|
+
if not config.workdir:
|
|
138
|
+
missing.append("workdir")
|
|
139
|
+
if not config.claude.analyze:
|
|
140
|
+
missing.append("agents.claude.analyze")
|
|
141
|
+
if not config.claude.launch:
|
|
142
|
+
missing.append("agents.claude.launch")
|
|
143
|
+
if not config.codex.analyze:
|
|
144
|
+
missing.append("agents.codex.analyze")
|
|
145
|
+
if not config.codex.launch:
|
|
146
|
+
missing.append("agents.codex.launch")
|
|
147
|
+
return missing
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
def _prompt_with_default(input_fn: Callable[[str], str], label: str, default: str) -> str:
|
|
151
|
+
response = input_fn(f"{label} [{default}]: ").strip()
|
|
152
|
+
return response or default
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def _prompt_required(input_fn: Callable[[str], str], label: str) -> str:
|
|
156
|
+
while True:
|
|
157
|
+
response = input_fn(f"{label}: ").strip()
|
|
158
|
+
if response:
|
|
159
|
+
return response
|
|
160
|
+
print(f"{label} is required.")
|
|
161
|
+
|
|
162
|
+
|
|
163
|
+
def _zellij_release_target() -> str:
|
|
164
|
+
machine = platform.machine()
|
|
165
|
+
if machine == "arm64":
|
|
166
|
+
arch = "aarch64"
|
|
167
|
+
elif machine in {"x86_64", "aarch64"}:
|
|
168
|
+
arch = machine
|
|
169
|
+
else:
|
|
170
|
+
raise RuntimeError(f"Unsupported CPU architecture for Zellij: {machine}")
|
|
171
|
+
|
|
172
|
+
system_name = platform.system()
|
|
173
|
+
if system_name == "Linux":
|
|
174
|
+
system = "unknown-linux-musl"
|
|
175
|
+
elif system_name == "Darwin":
|
|
176
|
+
system = "apple-darwin"
|
|
177
|
+
else:
|
|
178
|
+
raise RuntimeError(f"Unsupported operating system for Zellij: {system_name}")
|
|
179
|
+
return f"{arch}-{system}"
|
|
180
|
+
|
|
181
|
+
|
|
182
|
+
def _zellij_release_url() -> str:
|
|
183
|
+
target = _zellij_release_target()
|
|
184
|
+
return f"https://github.com/zellij-org/zellij/releases/latest/download/zellij-{target}.tar.gz"
|
|
185
|
+
|
|
186
|
+
|
|
187
|
+
def _download_bytes(url: str, *, urlopen_fn: Callable[[str], object]) -> bytes:
|
|
188
|
+
try:
|
|
189
|
+
with urlopen_fn(url) as response:
|
|
190
|
+
return response.read()
|
|
191
|
+
except OSError as error:
|
|
192
|
+
raise RuntimeError(f"Failed to download {url}: {error}") from error
|
|
193
|
+
|
|
194
|
+
|
|
195
|
+
def _write_executable(destination: Path, binary: bytes) -> str:
|
|
196
|
+
destination.parent.mkdir(parents=True, exist_ok=True)
|
|
197
|
+
destination.write_bytes(binary)
|
|
198
|
+
current_mode = destination.stat().st_mode
|
|
199
|
+
destination.chmod(current_mode | stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH)
|
|
200
|
+
return str(destination)
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def install_zellij_binary(
|
|
204
|
+
destination: Path = ZELLIJ_INSTALL_PATH,
|
|
205
|
+
*,
|
|
206
|
+
urlopen_fn: Callable[[str], object] = urllib.request.urlopen,
|
|
207
|
+
) -> str:
|
|
208
|
+
"""Download and install the latest Zellij release binary.
|
|
209
|
+
|
|
210
|
+
:param Path destination: Path where the executable should be installed.
|
|
211
|
+
:param urlopen_fn: Callable used to download the release archive.
|
|
212
|
+
"""
|
|
213
|
+
|
|
214
|
+
url = _zellij_release_url()
|
|
215
|
+
print(f"Downloading Zellij from {url}")
|
|
216
|
+
archive_bytes = _download_bytes(url, urlopen_fn=urlopen_fn)
|
|
217
|
+
|
|
218
|
+
try:
|
|
219
|
+
with tarfile.open(fileobj=BytesIO(archive_bytes), mode="r:gz") as archive:
|
|
220
|
+
member = next(
|
|
221
|
+
(
|
|
222
|
+
entry
|
|
223
|
+
for entry in archive.getmembers()
|
|
224
|
+
if Path(entry.name).name == "zellij" and entry.isfile()
|
|
225
|
+
),
|
|
226
|
+
None,
|
|
227
|
+
)
|
|
228
|
+
if member is None:
|
|
229
|
+
raise RuntimeError("Downloaded Zellij archive did not contain a zellij binary.")
|
|
230
|
+
extracted = archive.extractfile(member)
|
|
231
|
+
if extracted is None:
|
|
232
|
+
raise RuntimeError("Failed to extract the Zellij binary from the archive.")
|
|
233
|
+
binary = extracted.read()
|
|
234
|
+
except tarfile.TarError as error:
|
|
235
|
+
raise RuntimeError(f"Failed to extract Zellij archive: {error}") from error
|
|
236
|
+
|
|
237
|
+
return _write_executable(destination, binary)
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
def _gh_release_asset_patterns() -> tuple[str, str]:
|
|
241
|
+
machine = platform.machine()
|
|
242
|
+
if machine in {"x86_64", "amd64"}:
|
|
243
|
+
arch = "amd64"
|
|
244
|
+
elif machine in {"arm64", "aarch64"}:
|
|
245
|
+
arch = "arm64"
|
|
246
|
+
else:
|
|
247
|
+
raise RuntimeError(f"Unsupported CPU architecture for GitHub CLI: {machine}")
|
|
248
|
+
|
|
249
|
+
system_name = platform.system()
|
|
250
|
+
if system_name == "Linux":
|
|
251
|
+
os_name = "linux"
|
|
252
|
+
extension = ".tar.gz"
|
|
253
|
+
elif system_name == "Darwin":
|
|
254
|
+
os_name = "macOS"
|
|
255
|
+
extension = ".zip"
|
|
256
|
+
else:
|
|
257
|
+
raise RuntimeError(f"Unsupported operating system for GitHub CLI: {system_name}")
|
|
258
|
+
return f"_{os_name}_{arch}{extension}", extension
|
|
259
|
+
|
|
260
|
+
|
|
261
|
+
def _gh_release_download_url(
|
|
262
|
+
*,
|
|
263
|
+
urlopen_fn: Callable[[str], object] = urllib.request.urlopen,
|
|
264
|
+
) -> str:
|
|
265
|
+
archive_suffix, _extension = _gh_release_asset_patterns()
|
|
266
|
+
release_bytes = _download_bytes(GH_LATEST_RELEASE_API_URL, urlopen_fn=urlopen_fn)
|
|
267
|
+
try:
|
|
268
|
+
release = json.loads(release_bytes.decode("utf-8"))
|
|
269
|
+
except (UnicodeDecodeError, json.JSONDecodeError) as error:
|
|
270
|
+
raise RuntimeError(f"Failed to parse GitHub CLI release metadata: {error}") from error
|
|
271
|
+
assets = release.get("assets") if isinstance(release, dict) else None
|
|
272
|
+
if not isinstance(assets, list):
|
|
273
|
+
raise RuntimeError("GitHub CLI release metadata did not contain an assets list.")
|
|
274
|
+
for asset in assets:
|
|
275
|
+
if not isinstance(asset, dict):
|
|
276
|
+
continue
|
|
277
|
+
name = asset.get("name")
|
|
278
|
+
download_url = asset.get("browser_download_url")
|
|
279
|
+
if (
|
|
280
|
+
isinstance(name, str)
|
|
281
|
+
and name.endswith(archive_suffix)
|
|
282
|
+
and isinstance(download_url, str)
|
|
283
|
+
):
|
|
284
|
+
return download_url
|
|
285
|
+
raise RuntimeError(
|
|
286
|
+
f"GitHub CLI latest release did not contain an asset ending with {archive_suffix!r}."
|
|
287
|
+
)
|
|
288
|
+
|
|
289
|
+
|
|
290
|
+
def install_gh_binary(
|
|
291
|
+
destination: Path = GH_INSTALL_PATH,
|
|
292
|
+
*,
|
|
293
|
+
urlopen_fn: Callable[[str], object] = urllib.request.urlopen,
|
|
294
|
+
) -> str:
|
|
295
|
+
"""Download and install the latest GitHub CLI release binary.
|
|
296
|
+
|
|
297
|
+
:param Path destination: Path where the executable should be installed.
|
|
298
|
+
:param urlopen_fn: Callable used to download release metadata and archive bytes.
|
|
299
|
+
"""
|
|
300
|
+
|
|
301
|
+
download_url = _gh_release_download_url(urlopen_fn=urlopen_fn)
|
|
302
|
+
print(f"Downloading GitHub CLI from {download_url}")
|
|
303
|
+
archive_bytes = _download_bytes(download_url, urlopen_fn=urlopen_fn)
|
|
304
|
+
_archive_suffix, extension = _gh_release_asset_patterns()
|
|
305
|
+
|
|
306
|
+
try:
|
|
307
|
+
if extension == ".zip":
|
|
308
|
+
with zipfile.ZipFile(BytesIO(archive_bytes)) as archive:
|
|
309
|
+
member_name = next(
|
|
310
|
+
(
|
|
311
|
+
name
|
|
312
|
+
for name in archive.namelist()
|
|
313
|
+
if Path(name).name == "gh" and not name.endswith("/")
|
|
314
|
+
),
|
|
315
|
+
None,
|
|
316
|
+
)
|
|
317
|
+
if member_name is None:
|
|
318
|
+
raise RuntimeError("Downloaded GitHub CLI archive did not contain gh.")
|
|
319
|
+
binary = archive.read(member_name)
|
|
320
|
+
else:
|
|
321
|
+
with tarfile.open(fileobj=BytesIO(archive_bytes), mode="r:gz") as archive:
|
|
322
|
+
member = next(
|
|
323
|
+
(
|
|
324
|
+
entry
|
|
325
|
+
for entry in archive.getmembers()
|
|
326
|
+
if Path(entry.name).name == "gh" and entry.isfile()
|
|
327
|
+
),
|
|
328
|
+
None,
|
|
329
|
+
)
|
|
330
|
+
if member is None:
|
|
331
|
+
raise RuntimeError("Downloaded GitHub CLI archive did not contain gh.")
|
|
332
|
+
extracted = archive.extractfile(member)
|
|
333
|
+
if extracted is None:
|
|
334
|
+
raise RuntimeError("Failed to extract the GitHub CLI binary.")
|
|
335
|
+
binary = extracted.read()
|
|
336
|
+
except (tarfile.TarError, zipfile.BadZipFile) as error:
|
|
337
|
+
raise RuntimeError(f"Failed to extract GitHub CLI archive: {error}") from error
|
|
338
|
+
|
|
339
|
+
return _write_executable(destination, binary)
|
|
340
|
+
|
|
341
|
+
|
|
342
|
+
def configure(
|
|
343
|
+
path: Path = CONFIG_PATH,
|
|
344
|
+
*,
|
|
345
|
+
input_fn: Callable[[str], str] = input,
|
|
346
|
+
which_fn: Callable[[str], str | None] = shutil.which,
|
|
347
|
+
install_zellij_fn: Callable[[], str] | None = None,
|
|
348
|
+
install_gh_fn: Callable[[], str] | None = None,
|
|
349
|
+
) -> WorkdashConfig:
|
|
350
|
+
"""Interactive configuration that fills in missing fields.
|
|
351
|
+
|
|
352
|
+
:param Path path: Config file path.
|
|
353
|
+
:param input_fn: Callable used to prompt the user (default: builtin input).
|
|
354
|
+
:param which_fn: Callable used to detect commands on PATH (default: shutil.which).
|
|
355
|
+
"""
|
|
356
|
+
|
|
357
|
+
config = load_config(path)
|
|
358
|
+
install_zellij = install_zellij_fn or (
|
|
359
|
+
lambda: install_zellij_binary(path.parent / "bin" / "zellij")
|
|
360
|
+
)
|
|
361
|
+
install_gh = install_gh_fn or (lambda: install_gh_binary(path.parent / "bin" / "gh"))
|
|
362
|
+
|
|
363
|
+
detected_zellij = which_fn("zellij")
|
|
364
|
+
if detected_zellij:
|
|
365
|
+
print(f"Detected 'zellij' on PATH: {detected_zellij}")
|
|
366
|
+
else:
|
|
367
|
+
print(
|
|
368
|
+
f"Zellij is not on PATH. Installing a local Zellij binary from {_zellij_release_url()}."
|
|
369
|
+
)
|
|
370
|
+
print("To use a global Zellij instead, install it separately and make sure it is on PATH.")
|
|
371
|
+
installed_zellij = install_zellij()
|
|
372
|
+
print(f"Installed Zellij to: {installed_zellij}")
|
|
373
|
+
|
|
374
|
+
detected_gh = which_fn("gh")
|
|
375
|
+
if detected_gh:
|
|
376
|
+
print(f"Detected 'gh' on PATH: {detected_gh}")
|
|
377
|
+
else:
|
|
378
|
+
print(
|
|
379
|
+
f"GitHub CLI is not on PATH. Installing a local GitHub CLI binary from "
|
|
380
|
+
f"{GH_LATEST_RELEASE_PAGE_URL}."
|
|
381
|
+
)
|
|
382
|
+
print(
|
|
383
|
+
"To use a global GitHub CLI instead, install it separately and make sure it is on PATH."
|
|
384
|
+
)
|
|
385
|
+
installed_gh = install_gh()
|
|
386
|
+
print(f"Installed GitHub CLI to: {installed_gh}")
|
|
387
|
+
|
|
388
|
+
claude = config.claude
|
|
389
|
+
if not claude.analyze or not claude.launch:
|
|
390
|
+
if which_fn("claude"):
|
|
391
|
+
if not claude.analyze:
|
|
392
|
+
print(f"Detected 'claude' on PATH, using analyze: {_DEFAULT_CLAUDE_ANALYZE}")
|
|
393
|
+
if not claude.launch:
|
|
394
|
+
print(f"Detected 'claude' on PATH, using launch: {_DEFAULT_CLAUDE_LAUNCH}")
|
|
395
|
+
claude = AgentConfig(
|
|
396
|
+
analyze=claude.analyze or _DEFAULT_CLAUDE_ANALYZE,
|
|
397
|
+
launch=claude.launch or _DEFAULT_CLAUDE_LAUNCH,
|
|
398
|
+
)
|
|
399
|
+
else:
|
|
400
|
+
claude = AgentConfig(
|
|
401
|
+
analyze=claude.analyze
|
|
402
|
+
or _prompt_with_default(
|
|
403
|
+
input_fn, "Claude analyze command", _DEFAULT_CLAUDE_ANALYZE
|
|
404
|
+
),
|
|
405
|
+
launch=claude.launch
|
|
406
|
+
or _prompt_with_default(input_fn, "Claude launch command", _DEFAULT_CLAUDE_LAUNCH),
|
|
407
|
+
)
|
|
408
|
+
|
|
409
|
+
codex = config.codex
|
|
410
|
+
if not codex.analyze or not codex.launch:
|
|
411
|
+
if which_fn("codex"):
|
|
412
|
+
if not codex.analyze:
|
|
413
|
+
print(f"Detected 'codex' on PATH, using analyze: {_DEFAULT_CODEX_ANALYZE}")
|
|
414
|
+
if not codex.launch:
|
|
415
|
+
print(f"Detected 'codex' on PATH, using launch: {_DEFAULT_CODEX_LAUNCH}")
|
|
416
|
+
codex = AgentConfig(
|
|
417
|
+
analyze=codex.analyze or _DEFAULT_CODEX_ANALYZE,
|
|
418
|
+
launch=codex.launch or _DEFAULT_CODEX_LAUNCH,
|
|
419
|
+
)
|
|
420
|
+
else:
|
|
421
|
+
codex = AgentConfig(
|
|
422
|
+
analyze=codex.analyze
|
|
423
|
+
or _prompt_with_default(input_fn, "Codex analyze command", _DEFAULT_CODEX_ANALYZE),
|
|
424
|
+
launch=codex.launch
|
|
425
|
+
or _prompt_with_default(input_fn, "Codex launch command", _DEFAULT_CODEX_LAUNCH),
|
|
426
|
+
)
|
|
427
|
+
|
|
428
|
+
github_username = config.github_username
|
|
429
|
+
if not github_username:
|
|
430
|
+
github_username = _prompt_required(input_fn, "GitHub username")
|
|
431
|
+
|
|
432
|
+
workdir = config.workdir
|
|
433
|
+
if not workdir:
|
|
434
|
+
workdir = _prompt_with_default(input_fn, "Work directory", _DEFAULT_WORKDIR)
|
|
435
|
+
|
|
436
|
+
repositories = config.repositories
|
|
437
|
+
if not repositories and github_username:
|
|
438
|
+
repositories = (f"{github_username}/*",)
|
|
439
|
+
print(f"Repositories set to: {github_username}/*")
|
|
440
|
+
|
|
441
|
+
new_config = WorkdashConfig(
|
|
442
|
+
github_username=github_username,
|
|
443
|
+
claude=claude,
|
|
444
|
+
codex=codex,
|
|
445
|
+
repositories=repositories,
|
|
446
|
+
workdir=workdir,
|
|
447
|
+
)
|
|
448
|
+
save_config(new_config, path)
|
|
449
|
+
print(f"Configuration saved to {path}")
|
|
450
|
+
return new_config
|
|
@@ -14,10 +14,12 @@ from typing import Any, NoReturn
|
|
|
14
14
|
|
|
15
15
|
import markdown
|
|
16
16
|
|
|
17
|
+
from .config import LOCAL_BIN_PATH
|
|
17
18
|
from .models import WorkItem, WorkItemKind, WorkItemType
|
|
18
19
|
|
|
19
20
|
_PROMPTS_DIR = Path(__file__).parent / "prompts"
|
|
20
21
|
_BROWSER_OPEN_COMMANDS = ("xdg-open", "open")
|
|
22
|
+
_WORKDASH_LOCAL_BIN = LOCAL_BIN_PATH
|
|
21
23
|
|
|
22
24
|
|
|
23
25
|
def _load_prompt_template(name: str) -> str:
|
|
@@ -104,13 +106,35 @@ def _run_launch_command(command: list[str], *, context: str) -> None:
|
|
|
104
106
|
raise RuntimeError(f"{context}: {message}") from error
|
|
105
107
|
|
|
106
108
|
|
|
107
|
-
def
|
|
109
|
+
def _path_with_workdash_local_bin(env_path: str | None = None) -> str:
|
|
110
|
+
path = env_path if env_path is not None else os.environ.get("PATH", "")
|
|
111
|
+
local_bin = str(_WORKDASH_LOCAL_BIN)
|
|
112
|
+
if not path:
|
|
113
|
+
return local_bin
|
|
114
|
+
parts = path.split(os.pathsep)
|
|
115
|
+
if local_bin in parts:
|
|
116
|
+
return path
|
|
117
|
+
return os.pathsep.join([path, local_bin])
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def inject_workdash_local_bin_into_path() -> None:
|
|
121
|
+
"""Add workdash's local bin directory to PATH without displacing global tools."""
|
|
122
|
+
|
|
123
|
+
os.environ["PATH"] = _path_with_workdash_local_bin()
|
|
124
|
+
|
|
125
|
+
|
|
126
|
+
def _resolve_zellij_binary() -> str:
|
|
127
|
+
inject_workdash_local_bin_into_path()
|
|
108
128
|
zellij = shutil.which("zellij")
|
|
109
129
|
if zellij is None:
|
|
110
130
|
raise RuntimeError(
|
|
111
|
-
"zellij is not installed or not
|
|
112
|
-
"Install it from https://zellij.dev/ or run 'workdash --direct'."
|
|
131
|
+
"zellij is not installed or not configured. Run 'workdash --configure' to set it up."
|
|
113
132
|
)
|
|
133
|
+
return zellij
|
|
134
|
+
|
|
135
|
+
|
|
136
|
+
def exec_zellij_wrapped_workdash(argv: Sequence[str] | None) -> NoReturn:
|
|
137
|
+
zellij = _resolve_zellij_binary()
|
|
114
138
|
|
|
115
139
|
original_args = list(argv) if argv is not None else sys.argv[1:]
|
|
116
140
|
session_name = f"workdash-{secrets.token_hex(4)}"
|
|
@@ -171,18 +195,20 @@ def _write_zellij_startup_layout(workdash_command: Sequence[str], *, session_nam
|
|
|
171
195
|
return layout_file.name
|
|
172
196
|
|
|
173
197
|
|
|
174
|
-
def _launch_zellij_command(
|
|
198
|
+
def _launch_zellij_command(
|
|
199
|
+
repo_path: str,
|
|
200
|
+
command: list[str],
|
|
201
|
+
*,
|
|
202
|
+
context: str,
|
|
203
|
+
) -> None:
|
|
175
204
|
if not os.getenv("ZELLIJ"):
|
|
176
205
|
raise RuntimeError(
|
|
177
206
|
f"{context}: terminal-backed work actions require an active Zellij session. "
|
|
178
207
|
"Start workdash normally, or run it inside Zellij."
|
|
179
208
|
)
|
|
180
|
-
|
|
181
|
-
raise RuntimeError(
|
|
182
|
-
"zellij is not installed or not on PATH. Download it from https://zellij.dev"
|
|
183
|
-
)
|
|
209
|
+
zellij = _resolve_zellij_binary()
|
|
184
210
|
_run_launch_command(
|
|
185
|
-
[
|
|
211
|
+
[zellij, "action", "new-pane", "--cwd", repo_path, "--", *command],
|
|
186
212
|
context=context,
|
|
187
213
|
)
|
|
188
214
|
|