opencode2-pr-sidebar 0.0.0-stage → 0.1.4
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.
- package/LICENSE +21 -0
- package/README.md +85 -2
- package/dist/model.js +676 -0
- package/dist/tui.js +420 -0
- package/docs/assets/card.gif +0 -0
- package/package.json +77 -5
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 Krzysztof Karczewski
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
CHANGED
|
@@ -1,3 +1,86 @@
|
|
|
1
|
-
#
|
|
1
|
+
# pr-sidebar
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
[](https://github.com/karczews/opencode-pr-sidebar/actions/workflows/check.yml?query=branch%3Amain)
|
|
4
|
+
|
|
5
|
+
Current-branch GitHub pull request card for the OpenCode TUI sidebar.
|
|
6
|
+
|
|
7
|
+
It shows the pull request for the working directory's current branch: lifecycle,
|
|
8
|
+
review, checks, merge readiness, and activity at a glance. The card is read-only,
|
|
9
|
+
uses your authenticated GitHub CLI, and makes no model calls. The full behavior
|
|
10
|
+
contract lives in
|
|
11
|
+
[`openspec/specs/pr-sidebar/spec.md`](openspec/specs/pr-sidebar/spec.md).
|
|
12
|
+
|
|
13
|
+

|
|
14
|
+
|
|
15
|
+
## Requirements
|
|
16
|
+
|
|
17
|
+
- OpenCode v2 with TUI plugin support (`>= 2.2.6`; uses the V2
|
|
18
|
+
`Plugin.define({ setup })` TUI API).
|
|
19
|
+
- `git` and an authenticated `gh` (`gh auth login`) on the TUI process's `PATH`.
|
|
20
|
+
|
|
21
|
+
## Install
|
|
22
|
+
|
|
23
|
+
### From GitHub
|
|
24
|
+
|
|
25
|
+
<!-- x-release-please-start-version -->
|
|
26
|
+
```sh
|
|
27
|
+
opencode plugin add github:karczews/opencode-pr-sidebar
|
|
28
|
+
# pin a release tag if you prefer:
|
|
29
|
+
opencode plugin add 'github:karczews/opencode-pr-sidebar#v0.1.4'
|
|
30
|
+
```
|
|
31
|
+
<!-- x-release-please-end -->
|
|
32
|
+
|
|
33
|
+
This is a TUI-only plugin — `plugin add` records it in
|
|
34
|
+
`~/.config/opencode/cli.json` automatically (not `opencode.json`). Verify with
|
|
35
|
+
`opencode plugin list`.
|
|
36
|
+
|
|
37
|
+
Restart OpenCode. The Plugins dialog shows `pr-sidebar` once it loads.
|
|
38
|
+
|
|
39
|
+
### From a local checkout
|
|
40
|
+
|
|
41
|
+
Add the directory to `~/.config/opencode/cli.json`:
|
|
42
|
+
|
|
43
|
+
```json
|
|
44
|
+
{
|
|
45
|
+
"$schema": "https://opencode.ai/v2/cli.json",
|
|
46
|
+
"plugins": ["/absolute/path/to/opencode-pr-sidebar"]
|
|
47
|
+
}
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
A local path is a config entry, not an `opencode plugin add` target. See
|
|
51
|
+
[`docs/plugin-distribution.md`](docs/plugin-distribution.md) for packaging
|
|
52
|
+
notes.
|
|
53
|
+
|
|
54
|
+
## Walkthrough
|
|
55
|
+
|
|
56
|
+
1. Open a repository checkout whose current branch has a pull request.
|
|
57
|
+
2. The card appears in the sidebar, expanded:
|
|
58
|
+
|
|
59
|
+
```
|
|
60
|
+
+-------------------------------------------+
|
|
61
|
+
| ▼ Pull Request |
|
|
62
|
+
| #42 Fix login (hyperlink, click to open) |
|
|
63
|
+
| feature -> main |
|
|
64
|
+
| Open |
|
|
65
|
+
| Review: Approved |
|
|
66
|
+
| Ready to merge |
|
|
67
|
+
| Checks: 3 passed / 1 failed / 2 pending |
|
|
68
|
+
| +120 / -30 / 8 files |
|
|
69
|
+
| 4 unresolved / 12 total comments |
|
|
70
|
+
| Updated 2h ago |
|
|
71
|
+
| Checked 1m ago |
|
|
72
|
+
| [ Refresh ] [ Copy URL ] [ Open ] |
|
|
73
|
+
+-------------------------------------------+
|
|
74
|
+
```
|
|
75
|
+
|
|
76
|
+
3. Click the title or `Open` to launch the pull request in your browser. When no
|
|
77
|
+
browser launcher is available, a toast shows the full URL so you can open it
|
|
78
|
+
manually.
|
|
79
|
+
4. Use `Copy URL` to put the full URL on the clipboard.
|
|
80
|
+
5. Use `Refresh` to update immediately; otherwise the card keeps itself current.
|
|
81
|
+
6. Click the header to collapse or expand the card. `ctrl+p` exposes the same
|
|
82
|
+
actions as `PR: Open on GitHub`, `PR: Copy URL`, and `PR: Refresh status`.
|
|
83
|
+
|
|
84
|
+
If the branch has no pull request, the card stays hidden. A failed first lookup
|
|
85
|
+
shows a short error, and a failed refresh keeps the last good data marked
|
|
86
|
+
`STALE`.
|
package/dist/model.js
ADDED
|
@@ -0,0 +1,676 @@
|
|
|
1
|
+
import { execFile } from "node:child_process";
|
|
2
|
+
// gh enum fields, with the fallbacks parsePRView normalizes unknowns to.
|
|
3
|
+
const REVIEW_DECISIONS = ["APPROVED", "CHANGES_REQUESTED", "REVIEW_REQUIRED", ""];
|
|
4
|
+
const MERGE_STATE_STATUSES = [
|
|
5
|
+
"BEHIND",
|
|
6
|
+
"BLOCKED",
|
|
7
|
+
"CLEAN",
|
|
8
|
+
"DIRTY",
|
|
9
|
+
"DRAFT",
|
|
10
|
+
"HAS_HOOKS",
|
|
11
|
+
"UNKNOWN",
|
|
12
|
+
"UNSTABLE",
|
|
13
|
+
];
|
|
14
|
+
const MERGEABLE_STATES = ["MERGEABLE", "CONFLICTING", "UNKNOWN"];
|
|
15
|
+
export const PR_VIEW_FIELDS = [
|
|
16
|
+
"url",
|
|
17
|
+
"number",
|
|
18
|
+
"title",
|
|
19
|
+
"state",
|
|
20
|
+
"isDraft",
|
|
21
|
+
"additions",
|
|
22
|
+
"deletions",
|
|
23
|
+
"changedFiles",
|
|
24
|
+
"headRefName",
|
|
25
|
+
"baseRefName",
|
|
26
|
+
"mergeable",
|
|
27
|
+
"mergeStateStatus",
|
|
28
|
+
"reviewDecision",
|
|
29
|
+
"statusCheckRollup",
|
|
30
|
+
"updatedAt",
|
|
31
|
+
].join(",");
|
|
32
|
+
// --- subprocess execution ---
|
|
33
|
+
const REPO_ENV_KEYS = [
|
|
34
|
+
"GH_REPO",
|
|
35
|
+
"GIT_DIR",
|
|
36
|
+
"GIT_WORK_TREE",
|
|
37
|
+
"GIT_COMMON_DIR",
|
|
38
|
+
"GIT_INDEX_FILE",
|
|
39
|
+
];
|
|
40
|
+
export function run(file, args, { cwd, signal, input, timeoutMs = 15_000 }) {
|
|
41
|
+
return new Promise((resolve, reject) => {
|
|
42
|
+
const env = {
|
|
43
|
+
...process.env,
|
|
44
|
+
GH_PROMPT_DISABLED: "1",
|
|
45
|
+
GIT_TERMINAL_PROMPT: "0",
|
|
46
|
+
NO_COLOR: "1",
|
|
47
|
+
};
|
|
48
|
+
// A launching shell's overrides must not select another worktree or repository.
|
|
49
|
+
for (const key of REPO_ENV_KEYS) {
|
|
50
|
+
delete env[key];
|
|
51
|
+
}
|
|
52
|
+
const child = execFile(file, args, { cwd, env, signal, timeout: timeoutMs, maxBuffer: 2 * 1024 * 1024 }, (error, stdout, stderr) => {
|
|
53
|
+
if (error) {
|
|
54
|
+
reject(Object.assign(error, { stderr }));
|
|
55
|
+
}
|
|
56
|
+
else {
|
|
57
|
+
resolve(stdout);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
child.stdin?.on("error", () => { });
|
|
61
|
+
child.stdin?.end(input);
|
|
62
|
+
});
|
|
63
|
+
}
|
|
64
|
+
export async function detectRepo(directory, signal, execute = run) {
|
|
65
|
+
try {
|
|
66
|
+
const out = await execute("git", ["rev-parse", "--show-toplevel", "--abbrev-ref", "HEAD"], {
|
|
67
|
+
cwd: directory,
|
|
68
|
+
signal,
|
|
69
|
+
});
|
|
70
|
+
const [root, branch] = out.trim().split("\n");
|
|
71
|
+
if (!root || !branch) {
|
|
72
|
+
return null;
|
|
73
|
+
}
|
|
74
|
+
return { root, branch };
|
|
75
|
+
}
|
|
76
|
+
catch {
|
|
77
|
+
return null;
|
|
78
|
+
}
|
|
79
|
+
}
|
|
80
|
+
export async function fetchPRView(directory, signal, execute = run) {
|
|
81
|
+
return execute("gh", ["pr", "view", "--json", PR_VIEW_FIELDS], { cwd: directory, signal });
|
|
82
|
+
}
|
|
83
|
+
export function countsQuery(ref) {
|
|
84
|
+
if (!Number.isInteger(ref.number) || ref.number < 1) {
|
|
85
|
+
throw new Error("Invalid PR number");
|
|
86
|
+
}
|
|
87
|
+
return `query {
|
|
88
|
+
repository(owner: ${JSON.stringify(ref.owner)}, name: ${JSON.stringify(ref.repo)}) {
|
|
89
|
+
pullRequest(number: ${ref.number}) {
|
|
90
|
+
comments(first: 1) { totalCount }
|
|
91
|
+
reviews(first: 1) { totalCount }
|
|
92
|
+
reviewThreads(first: 100) { totalCount nodes { isResolved } }
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}`;
|
|
96
|
+
}
|
|
97
|
+
export async function fetchCounts(ref, directory, signal, execute = run) {
|
|
98
|
+
return execute("gh", ["api", "graphql", "-f", `query=${countsQuery(ref)}`], {
|
|
99
|
+
cwd: directory,
|
|
100
|
+
signal,
|
|
101
|
+
});
|
|
102
|
+
}
|
|
103
|
+
function isRecord(value) {
|
|
104
|
+
return typeof value === "object" && value !== null;
|
|
105
|
+
}
|
|
106
|
+
function asRecord(value, label) {
|
|
107
|
+
if (!isRecord(value)) {
|
|
108
|
+
throw new Error(label);
|
|
109
|
+
}
|
|
110
|
+
return value;
|
|
111
|
+
}
|
|
112
|
+
function asString(data, key) {
|
|
113
|
+
const value = data[key];
|
|
114
|
+
if (typeof value !== "string") {
|
|
115
|
+
throw new Error(`Invalid PR response: ${key}`);
|
|
116
|
+
}
|
|
117
|
+
return value;
|
|
118
|
+
}
|
|
119
|
+
function optionalString(value) {
|
|
120
|
+
return typeof value === "string" ? value : undefined;
|
|
121
|
+
}
|
|
122
|
+
function oneOf(value, allowed, fallback) {
|
|
123
|
+
return allowed.includes(value) ? value : fallback;
|
|
124
|
+
}
|
|
125
|
+
export function clean(value) {
|
|
126
|
+
return (String(value ?? "")
|
|
127
|
+
// biome-ignore lint/suspicious/noControlCharactersInRegex: strip terminal controls and bidi overrides from host-provided text.
|
|
128
|
+
.replace(/[\x00-\x1f\x7f-\x9f\u202a-\u202e\u2066-\u2069]/g, " ")
|
|
129
|
+
.replace(/\s+/g, " ")
|
|
130
|
+
.trim());
|
|
131
|
+
}
|
|
132
|
+
export function splitPRUrl(url) {
|
|
133
|
+
const parsed = new URL(url);
|
|
134
|
+
if (parsed.protocol !== "https:" || parsed.username || parsed.password) {
|
|
135
|
+
throw new Error("Invalid PR URL");
|
|
136
|
+
}
|
|
137
|
+
const match = /^\/([^/]+)\/([^/]+)\/pull\/(\d+)$/.exec(parsed.pathname);
|
|
138
|
+
if (!match) {
|
|
139
|
+
throw new Error("Invalid PR URL");
|
|
140
|
+
}
|
|
141
|
+
const [, owner, repo, num] = match;
|
|
142
|
+
if (!owner || !repo || !num) {
|
|
143
|
+
throw new Error("Invalid PR URL");
|
|
144
|
+
}
|
|
145
|
+
return { owner, repo, number: Number(num) };
|
|
146
|
+
}
|
|
147
|
+
function asNonNegativeInt(value, label) {
|
|
148
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 0) {
|
|
149
|
+
throw new Error(`Invalid PR response: ${label}`);
|
|
150
|
+
}
|
|
151
|
+
return value;
|
|
152
|
+
}
|
|
153
|
+
function asPositiveInt(value, label) {
|
|
154
|
+
if (typeof value !== "number" || !Number.isInteger(value) || value < 1) {
|
|
155
|
+
throw new Error(`Invalid PR response: ${label}`);
|
|
156
|
+
}
|
|
157
|
+
return value;
|
|
158
|
+
}
|
|
159
|
+
export function parsePRView(text) {
|
|
160
|
+
let data;
|
|
161
|
+
try {
|
|
162
|
+
data = JSON.parse(text);
|
|
163
|
+
}
|
|
164
|
+
catch {
|
|
165
|
+
throw new Error("Invalid PR response: not JSON");
|
|
166
|
+
}
|
|
167
|
+
if (!isRecord(data)) {
|
|
168
|
+
throw new Error("Invalid PR response");
|
|
169
|
+
}
|
|
170
|
+
const number = asPositiveInt(data.number, "number");
|
|
171
|
+
if (data.state !== "OPEN" && data.state !== "CLOSED" && data.state !== "MERGED") {
|
|
172
|
+
throw new Error("Invalid PR response: state");
|
|
173
|
+
}
|
|
174
|
+
const url = asString(data, "url");
|
|
175
|
+
const parts = splitPRUrl(url);
|
|
176
|
+
if (parts.number !== number) {
|
|
177
|
+
throw new Error("Invalid PR response: url number mismatch");
|
|
178
|
+
}
|
|
179
|
+
if (typeof data.isDraft !== "boolean") {
|
|
180
|
+
throw new Error("Invalid PR response: isDraft");
|
|
181
|
+
}
|
|
182
|
+
if (!Array.isArray(data.statusCheckRollup)) {
|
|
183
|
+
throw new Error("Invalid PR response: statusCheckRollup");
|
|
184
|
+
}
|
|
185
|
+
const rollup = [];
|
|
186
|
+
for (const entry of data.statusCheckRollup) {
|
|
187
|
+
if (isRecord(entry)) {
|
|
188
|
+
rollup.push({
|
|
189
|
+
__typename: optionalString(entry.__typename),
|
|
190
|
+
name: optionalString(entry.name),
|
|
191
|
+
context: optionalString(entry.context),
|
|
192
|
+
state: optionalString(entry.state),
|
|
193
|
+
status: optionalString(entry.status),
|
|
194
|
+
conclusion: optionalString(entry.conclusion),
|
|
195
|
+
});
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
return {
|
|
199
|
+
number,
|
|
200
|
+
url,
|
|
201
|
+
title: asString(data, "title"),
|
|
202
|
+
state: data.state,
|
|
203
|
+
isDraft: data.isDraft,
|
|
204
|
+
headRefName: asString(data, "headRefName"),
|
|
205
|
+
baseRefName: asString(data, "baseRefName"),
|
|
206
|
+
additions: asNonNegativeInt(data.additions, "additions"),
|
|
207
|
+
deletions: asNonNegativeInt(data.deletions, "deletions"),
|
|
208
|
+
changedFiles: asNonNegativeInt(data.changedFiles, "changedFiles"),
|
|
209
|
+
updatedAt: asString(data, "updatedAt"),
|
|
210
|
+
mergeStateStatus: oneOf(data.mergeStateStatus, MERGE_STATE_STATUSES, "UNKNOWN"),
|
|
211
|
+
mergeable: oneOf(data.mergeable, MERGEABLE_STATES, "UNKNOWN"),
|
|
212
|
+
reviewDecision: oneOf(data.reviewDecision, REVIEW_DECISIONS, ""),
|
|
213
|
+
statusCheckRollup: rollup,
|
|
214
|
+
};
|
|
215
|
+
}
|
|
216
|
+
export function parseCounts(text) {
|
|
217
|
+
let data;
|
|
218
|
+
try {
|
|
219
|
+
data = JSON.parse(text);
|
|
220
|
+
}
|
|
221
|
+
catch {
|
|
222
|
+
throw new Error("Invalid counts response: not JSON");
|
|
223
|
+
}
|
|
224
|
+
const root = asRecord(data, "Invalid counts response");
|
|
225
|
+
const payload = asRecord(root.data, "Invalid counts response: data");
|
|
226
|
+
const repository = asRecord(payload.repository, "Invalid counts response: repository");
|
|
227
|
+
const pr = asRecord(repository.pullRequest, "Invalid counts response: pullRequest");
|
|
228
|
+
const totalOf = (key) => {
|
|
229
|
+
const section = asRecord(pr[key], `Invalid counts response: ${key}`);
|
|
230
|
+
return asNonNegativeInt(section.totalCount, key);
|
|
231
|
+
};
|
|
232
|
+
const comments = totalOf("comments");
|
|
233
|
+
const reviews = totalOf("reviews");
|
|
234
|
+
const threadsSection = asRecord(pr.reviewThreads, "Invalid counts response: reviewThreads");
|
|
235
|
+
const threads = asNonNegativeInt(threadsSection.totalCount, "reviewThreads");
|
|
236
|
+
if (!Array.isArray(threadsSection.nodes)) {
|
|
237
|
+
throw new Error("Invalid counts response: reviewThreads nodes");
|
|
238
|
+
}
|
|
239
|
+
// Lower bound over the first page when totalCount exceeds the fetched nodes.
|
|
240
|
+
let unresolved = 0;
|
|
241
|
+
for (const node of threadsSection.nodes) {
|
|
242
|
+
if (isRecord(node) && node.isResolved === false) {
|
|
243
|
+
unresolved++;
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
return {
|
|
247
|
+
unresolvedThreads: unresolved,
|
|
248
|
+
totalComments: comments + reviews + threads,
|
|
249
|
+
};
|
|
250
|
+
}
|
|
251
|
+
export function errorKind(error) {
|
|
252
|
+
const detail = error && typeof error === "object"
|
|
253
|
+
? error
|
|
254
|
+
: {};
|
|
255
|
+
const text = String(detail.stderr ?? detail.message ?? "");
|
|
256
|
+
if (/no pull requests? found|no GitHub remotes|none of the git remotes.*GitHub/i.test(text)) {
|
|
257
|
+
return "absent";
|
|
258
|
+
}
|
|
259
|
+
if (detail.code === "ENOENT") {
|
|
260
|
+
return "cli-missing";
|
|
261
|
+
}
|
|
262
|
+
if (/auth login|authentication|HTTP 401|Bad credentials|not logged/i.test(text)) {
|
|
263
|
+
return "auth";
|
|
264
|
+
}
|
|
265
|
+
if (/rate limit/i.test(text)) {
|
|
266
|
+
return "rate-limit";
|
|
267
|
+
}
|
|
268
|
+
return "refresh-failed";
|
|
269
|
+
}
|
|
270
|
+
const FAILED_CONCLUSIONS = new Set([
|
|
271
|
+
"FAILURE",
|
|
272
|
+
"CANCELLED",
|
|
273
|
+
"TIMED_OUT",
|
|
274
|
+
"ACTION_REQUIRED",
|
|
275
|
+
"STARTUP_FAILURE",
|
|
276
|
+
"STALE",
|
|
277
|
+
]);
|
|
278
|
+
function classifyStatusContext(check) {
|
|
279
|
+
if (check.state === "SUCCESS") {
|
|
280
|
+
return "passed";
|
|
281
|
+
}
|
|
282
|
+
if (check.state === "FAILURE" || check.state === "ERROR") {
|
|
283
|
+
return "failed";
|
|
284
|
+
}
|
|
285
|
+
if (check.state === "SKIPPED") {
|
|
286
|
+
return "skipped";
|
|
287
|
+
}
|
|
288
|
+
return "pending";
|
|
289
|
+
}
|
|
290
|
+
function classifyCheckRun(check) {
|
|
291
|
+
if (check.status !== "COMPLETED") {
|
|
292
|
+
return "pending";
|
|
293
|
+
}
|
|
294
|
+
if (check.conclusion === "SUCCESS") {
|
|
295
|
+
return "passed";
|
|
296
|
+
}
|
|
297
|
+
if (check.conclusion === "SKIPPED" || check.conclusion === "NEUTRAL") {
|
|
298
|
+
return "skipped";
|
|
299
|
+
}
|
|
300
|
+
if (check.conclusion != null && FAILED_CONCLUSIONS.has(check.conclusion)) {
|
|
301
|
+
return "failed";
|
|
302
|
+
}
|
|
303
|
+
// Unknown or missing conclusion: never invent a pass or a failure.
|
|
304
|
+
return "pending";
|
|
305
|
+
}
|
|
306
|
+
function classifyCheck(check) {
|
|
307
|
+
return check.__typename === "StatusContext"
|
|
308
|
+
? classifyStatusContext(check)
|
|
309
|
+
: classifyCheckRun(check);
|
|
310
|
+
}
|
|
311
|
+
export function summarizeChecks(rollup) {
|
|
312
|
+
const counts = { passed: 0, failed: 0, pending: 0, skipped: 0 };
|
|
313
|
+
for (const check of rollup) {
|
|
314
|
+
counts[classifyCheck(check)]++;
|
|
315
|
+
}
|
|
316
|
+
return counts;
|
|
317
|
+
}
|
|
318
|
+
export function checksLineOf(counts) {
|
|
319
|
+
if (counts.passed + counts.failed + counts.pending + counts.skipped === 0) {
|
|
320
|
+
return "No checks reported";
|
|
321
|
+
}
|
|
322
|
+
let line = `Checks: ${counts.passed} passed / ${counts.failed} failed / ${counts.pending} pending`;
|
|
323
|
+
if (counts.skipped > 0) {
|
|
324
|
+
line += ` / ${counts.skipped} skipped`;
|
|
325
|
+
}
|
|
326
|
+
return line;
|
|
327
|
+
}
|
|
328
|
+
export const summarizeReview = {
|
|
329
|
+
APPROVED: "Approved",
|
|
330
|
+
CHANGES_REQUESTED: "Changes requested",
|
|
331
|
+
REVIEW_REQUIRED: "Review required",
|
|
332
|
+
"": "No review decision",
|
|
333
|
+
};
|
|
334
|
+
export function lifecycleOf(pr) {
|
|
335
|
+
if (pr.state === "MERGED") {
|
|
336
|
+
return "Merged";
|
|
337
|
+
}
|
|
338
|
+
if (pr.state === "CLOSED") {
|
|
339
|
+
return "Closed";
|
|
340
|
+
}
|
|
341
|
+
return pr.isDraft ? "Draft" : "Open";
|
|
342
|
+
}
|
|
343
|
+
const MERGE_LINES = [
|
|
344
|
+
"Merged",
|
|
345
|
+
"Closed without merging",
|
|
346
|
+
"Blocked: draft",
|
|
347
|
+
"Blocked: merge conflicts",
|
|
348
|
+
"Changes requested",
|
|
349
|
+
"Blocked by repository rules",
|
|
350
|
+
"Behind base branch",
|
|
351
|
+
"Checks not passing",
|
|
352
|
+
"Merge hooks must pass",
|
|
353
|
+
"Awaiting required review",
|
|
354
|
+
"Ready to merge",
|
|
355
|
+
"Merge status unknown",
|
|
356
|
+
];
|
|
357
|
+
export function mergeLineOf(pr) {
|
|
358
|
+
// Order matters: the first matching blocker wins.
|
|
359
|
+
if (pr.state === "MERGED") {
|
|
360
|
+
return "Merged";
|
|
361
|
+
}
|
|
362
|
+
if (pr.state === "CLOSED") {
|
|
363
|
+
return "Closed without merging";
|
|
364
|
+
}
|
|
365
|
+
if (pr.isDraft || pr.mergeStateStatus === "DRAFT") {
|
|
366
|
+
return "Blocked: draft";
|
|
367
|
+
}
|
|
368
|
+
if (pr.mergeable === "CONFLICTING" || pr.mergeStateStatus === "DIRTY") {
|
|
369
|
+
return "Blocked: merge conflicts";
|
|
370
|
+
}
|
|
371
|
+
if (pr.reviewDecision === "CHANGES_REQUESTED") {
|
|
372
|
+
return "Changes requested";
|
|
373
|
+
}
|
|
374
|
+
if (pr.mergeStateStatus === "BLOCKED") {
|
|
375
|
+
return "Blocked by repository rules";
|
|
376
|
+
}
|
|
377
|
+
if (pr.mergeStateStatus === "BEHIND") {
|
|
378
|
+
return "Behind base branch";
|
|
379
|
+
}
|
|
380
|
+
if (pr.mergeStateStatus === "UNSTABLE") {
|
|
381
|
+
return "Checks not passing";
|
|
382
|
+
}
|
|
383
|
+
if (pr.mergeStateStatus === "HAS_HOOKS") {
|
|
384
|
+
return "Merge hooks must pass";
|
|
385
|
+
}
|
|
386
|
+
if (pr.reviewDecision === "REVIEW_REQUIRED") {
|
|
387
|
+
return "Awaiting required review";
|
|
388
|
+
}
|
|
389
|
+
if (pr.mergeStateStatus === "CLEAN" && pr.mergeable === "MERGEABLE") {
|
|
390
|
+
return "Ready to merge";
|
|
391
|
+
}
|
|
392
|
+
return "Merge status unknown";
|
|
393
|
+
}
|
|
394
|
+
// The record must cover every MergeLine, so adding a merge line forces a choice of tone.
|
|
395
|
+
export const MERGE_TONE = {
|
|
396
|
+
Merged: "success",
|
|
397
|
+
"Closed without merging": "muted",
|
|
398
|
+
"Blocked: draft": "warning",
|
|
399
|
+
"Blocked: merge conflicts": "warning",
|
|
400
|
+
"Changes requested": "warning",
|
|
401
|
+
"Blocked by repository rules": "warning",
|
|
402
|
+
"Behind base branch": "warning",
|
|
403
|
+
"Checks not passing": "warning",
|
|
404
|
+
"Merge hooks must pass": "warning",
|
|
405
|
+
"Awaiting required review": "warning",
|
|
406
|
+
"Ready to merge": "success",
|
|
407
|
+
"Merge status unknown": "muted",
|
|
408
|
+
};
|
|
409
|
+
export function ageOf(time, now = Date.now()) {
|
|
410
|
+
const timestamp = new Date(time ?? Number.NaN).getTime();
|
|
411
|
+
const seconds = Math.max(0, Math.floor((now - timestamp) / 1000));
|
|
412
|
+
if (!Number.isFinite(seconds)) {
|
|
413
|
+
return "unknown";
|
|
414
|
+
}
|
|
415
|
+
if (seconds < 60) {
|
|
416
|
+
return "just now";
|
|
417
|
+
}
|
|
418
|
+
if (seconds < 3600) {
|
|
419
|
+
return `${Math.floor(seconds / 60)}m ago`;
|
|
420
|
+
}
|
|
421
|
+
if (seconds < 86_400) {
|
|
422
|
+
return `${Math.floor(seconds / 3600)}h ago`;
|
|
423
|
+
}
|
|
424
|
+
return `${Math.floor(seconds / 86_400)}d ago`;
|
|
425
|
+
}
|
|
426
|
+
export function summarize(pr) {
|
|
427
|
+
return {
|
|
428
|
+
lifecycle: lifecycleOf(pr),
|
|
429
|
+
review: summarizeReview[pr.reviewDecision],
|
|
430
|
+
checks: summarizeChecks(pr.statusCheckRollup),
|
|
431
|
+
merge: mergeLineOf(pr),
|
|
432
|
+
};
|
|
433
|
+
}
|
|
434
|
+
const GITHUB_THROTTLE_MS = 60_000;
|
|
435
|
+
const GITHUB_ACTIVITY_THROTTLE_MS = 10_000;
|
|
436
|
+
export const displayError = {
|
|
437
|
+
absent: "PR refresh failed",
|
|
438
|
+
"cli-missing": "GitHub CLI unavailable",
|
|
439
|
+
auth: "GitHub authentication required",
|
|
440
|
+
"rate-limit": "GitHub rate limit reached",
|
|
441
|
+
"refresh-failed": "PR refresh failed",
|
|
442
|
+
};
|
|
443
|
+
export function createMonitor({ directory, publish, execute = run, now = Date.now, }) {
|
|
444
|
+
let current = {
|
|
445
|
+
pr: null,
|
|
446
|
+
error: "",
|
|
447
|
+
fetchedAt: 0,
|
|
448
|
+
now: now(),
|
|
449
|
+
loading: false,
|
|
450
|
+
};
|
|
451
|
+
let key = "";
|
|
452
|
+
let version = 0;
|
|
453
|
+
let stopped = false;
|
|
454
|
+
let lastFetchAt = 0;
|
|
455
|
+
let request;
|
|
456
|
+
let detection;
|
|
457
|
+
// Serialize cycles so overlapping ticks cannot interleave fetches.
|
|
458
|
+
let tail = Promise.resolve();
|
|
459
|
+
const emit = (patch) => {
|
|
460
|
+
current = { ...current, ...patch, now: now() };
|
|
461
|
+
publish(current);
|
|
462
|
+
};
|
|
463
|
+
const reset = (next) => {
|
|
464
|
+
key = next;
|
|
465
|
+
version++;
|
|
466
|
+
request?.abort();
|
|
467
|
+
request = undefined;
|
|
468
|
+
detection?.abort();
|
|
469
|
+
detection = undefined;
|
|
470
|
+
lastFetchAt = 0;
|
|
471
|
+
emit({ pr: null, error: "", fetchedAt: 0, loading: false });
|
|
472
|
+
};
|
|
473
|
+
const isStale = (expected, cwd, signal) => stopped || expected !== version || directory() !== cwd || signal.aborted;
|
|
474
|
+
// The context (empty cwd, non-repo) yields nothing: drop whatever an older context left.
|
|
475
|
+
const resetIfKey = () => {
|
|
476
|
+
if (key) {
|
|
477
|
+
reset("");
|
|
478
|
+
}
|
|
479
|
+
};
|
|
480
|
+
// Empty or changed directory: clear anything an older context published.
|
|
481
|
+
const currentDirectory = () => {
|
|
482
|
+
const cwd = directory();
|
|
483
|
+
if (!cwd) {
|
|
484
|
+
resetIfKey();
|
|
485
|
+
return "";
|
|
486
|
+
}
|
|
487
|
+
if (current.directory !== cwd) {
|
|
488
|
+
reset("");
|
|
489
|
+
emit({ directory: cwd });
|
|
490
|
+
}
|
|
491
|
+
return cwd;
|
|
492
|
+
};
|
|
493
|
+
// The detection AbortController is tracked so a reset or stop can cancel it.
|
|
494
|
+
const detect = async (cwd) => {
|
|
495
|
+
const detectController = new AbortController();
|
|
496
|
+
detection = detectController;
|
|
497
|
+
try {
|
|
498
|
+
return await detectRepo(cwd, detectController.signal, execute);
|
|
499
|
+
}
|
|
500
|
+
catch {
|
|
501
|
+
return null;
|
|
502
|
+
}
|
|
503
|
+
finally {
|
|
504
|
+
if (detection === detectController) {
|
|
505
|
+
detection = undefined;
|
|
506
|
+
}
|
|
507
|
+
}
|
|
508
|
+
};
|
|
509
|
+
// Re-key the snapshot when the repo or branch changed, then publish the branch.
|
|
510
|
+
const syncRepo = (cwd, repo) => {
|
|
511
|
+
const next = JSON.stringify([cwd, repo.root, repo.branch]);
|
|
512
|
+
if (next !== key) {
|
|
513
|
+
reset(next);
|
|
514
|
+
}
|
|
515
|
+
if (current.branch !== repo.branch) {
|
|
516
|
+
emit({ branch: repo.branch });
|
|
517
|
+
}
|
|
518
|
+
};
|
|
519
|
+
// One GitHub request at a time; forced ticks cancel the in-flight one, others wait.
|
|
520
|
+
const shouldFetch = (force, activity) => {
|
|
521
|
+
if (request) {
|
|
522
|
+
if (!force) {
|
|
523
|
+
return false;
|
|
524
|
+
}
|
|
525
|
+
request.abort();
|
|
526
|
+
request = undefined;
|
|
527
|
+
}
|
|
528
|
+
else if (!force &&
|
|
529
|
+
lastFetchAt > 0 &&
|
|
530
|
+
now() - lastFetchAt < (activity ? GITHUB_ACTIVITY_THROTTLE_MS : GITHUB_THROTTLE_MS)) {
|
|
531
|
+
return false;
|
|
532
|
+
}
|
|
533
|
+
return true;
|
|
534
|
+
};
|
|
535
|
+
const publishError = (expected, cwd, signal, error) => {
|
|
536
|
+
if (isStale(expected, cwd, signal)) {
|
|
537
|
+
return;
|
|
538
|
+
}
|
|
539
|
+
const kind = errorKind(error);
|
|
540
|
+
if (kind === "absent") {
|
|
541
|
+
emit({ pr: null, error: "", fetchedAt: now() });
|
|
542
|
+
}
|
|
543
|
+
else {
|
|
544
|
+
emit({ error: displayError[kind] });
|
|
545
|
+
}
|
|
546
|
+
};
|
|
547
|
+
const fetchAndPublish = async (cwd, repo) => {
|
|
548
|
+
const expected = version;
|
|
549
|
+
const abort = new AbortController();
|
|
550
|
+
request = abort;
|
|
551
|
+
lastFetchAt = now();
|
|
552
|
+
emit({ loading: true });
|
|
553
|
+
try {
|
|
554
|
+
const viewText = await fetchPRView(cwd, abort.signal, execute);
|
|
555
|
+
if (isStale(expected, cwd, abort.signal)) {
|
|
556
|
+
return;
|
|
557
|
+
}
|
|
558
|
+
const parsed = parsePRView(viewText);
|
|
559
|
+
if (parsed.headRefName !== repo.branch) {
|
|
560
|
+
emit({ pr: null, error: "", fetchedAt: now() });
|
|
561
|
+
return;
|
|
562
|
+
}
|
|
563
|
+
const countsText = await fetchCounts(splitPRUrl(parsed.url), cwd, abort.signal, execute);
|
|
564
|
+
if (isStale(expected, cwd, abort.signal)) {
|
|
565
|
+
return;
|
|
566
|
+
}
|
|
567
|
+
const counts = parseCounts(countsText);
|
|
568
|
+
emit({ pr: { ...parsed, ...counts }, error: "", fetchedAt: now() });
|
|
569
|
+
}
|
|
570
|
+
catch (error) {
|
|
571
|
+
publishError(expected, cwd, abort.signal, error);
|
|
572
|
+
}
|
|
573
|
+
finally {
|
|
574
|
+
if (request === abort) {
|
|
575
|
+
request = undefined;
|
|
576
|
+
}
|
|
577
|
+
if (expected === version && !stopped) {
|
|
578
|
+
emit({ loading: false });
|
|
579
|
+
}
|
|
580
|
+
}
|
|
581
|
+
};
|
|
582
|
+
async function cycle(force, activity) {
|
|
583
|
+
if (stopped) {
|
|
584
|
+
return;
|
|
585
|
+
}
|
|
586
|
+
const cwd = currentDirectory();
|
|
587
|
+
if (!cwd) {
|
|
588
|
+
return;
|
|
589
|
+
}
|
|
590
|
+
const repo = await detect(cwd);
|
|
591
|
+
if (stopped || directory() !== cwd) {
|
|
592
|
+
return;
|
|
593
|
+
}
|
|
594
|
+
if (!repo) {
|
|
595
|
+
resetIfKey();
|
|
596
|
+
return;
|
|
597
|
+
}
|
|
598
|
+
syncRepo(cwd, repo);
|
|
599
|
+
if (repo.branch === "HEAD") {
|
|
600
|
+
return;
|
|
601
|
+
}
|
|
602
|
+
if (!shouldFetch(force, activity)) {
|
|
603
|
+
return;
|
|
604
|
+
}
|
|
605
|
+
await fetchAndPublish(cwd, repo);
|
|
606
|
+
}
|
|
607
|
+
return {
|
|
608
|
+
tick(force = false, activity = false) {
|
|
609
|
+
if (stopped) {
|
|
610
|
+
return;
|
|
611
|
+
}
|
|
612
|
+
tail = tail.then(() => cycle(force, activity)).catch(() => { });
|
|
613
|
+
},
|
|
614
|
+
stop() {
|
|
615
|
+
stopped = true;
|
|
616
|
+
version++;
|
|
617
|
+
request?.abort();
|
|
618
|
+
request = undefined;
|
|
619
|
+
detection?.abort();
|
|
620
|
+
detection = undefined;
|
|
621
|
+
},
|
|
622
|
+
};
|
|
623
|
+
}
|
|
624
|
+
const LAUNCHERS = {
|
|
625
|
+
darwin: "open",
|
|
626
|
+
linux: "xdg-open",
|
|
627
|
+
};
|
|
628
|
+
export async function openBrowser(url, cwd, signal, { env = process.env, platform = process.platform, execute = run } = {}) {
|
|
629
|
+
if (signal.aborted) {
|
|
630
|
+
return;
|
|
631
|
+
}
|
|
632
|
+
if (env.SSH_CONNECTION || env.SSH_CLIENT || env.SSH_TTY) {
|
|
633
|
+
return "SSH session detected. Open the URL below in your local browser.";
|
|
634
|
+
}
|
|
635
|
+
if (platform === "linux" && !env.DISPLAY && !env.WAYLAND_DISPLAY) {
|
|
636
|
+
return "No graphical display detected. Open the URL below in your browser.";
|
|
637
|
+
}
|
|
638
|
+
const launcher = LAUNCHERS[platform];
|
|
639
|
+
if (!launcher) {
|
|
640
|
+
return "Browser opening is unavailable here. Open the URL below in your browser.";
|
|
641
|
+
}
|
|
642
|
+
try {
|
|
643
|
+
await execute(launcher, [url], { cwd, signal });
|
|
644
|
+
}
|
|
645
|
+
catch {
|
|
646
|
+
if (!signal.aborted) {
|
|
647
|
+
return "Could not launch a browser. Open the URL below in your browser.";
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
return undefined;
|
|
651
|
+
}
|
|
652
|
+
function clipboardCommand(platform, env) {
|
|
653
|
+
if (platform === "darwin") {
|
|
654
|
+
return { file: "pbcopy", args: [] };
|
|
655
|
+
}
|
|
656
|
+
if (platform === "win32") {
|
|
657
|
+
return { file: "clip", args: [] };
|
|
658
|
+
}
|
|
659
|
+
if (env.WAYLAND_DISPLAY) {
|
|
660
|
+
return { file: "wl-copy", args: [] };
|
|
661
|
+
}
|
|
662
|
+
return { file: "xclip", args: ["-selection", "clipboard"] };
|
|
663
|
+
}
|
|
664
|
+
export async function copyToClipboard(text, cwd, signal, { env = process.env, platform = process.platform, execute = run } = {}) {
|
|
665
|
+
if (signal.aborted) {
|
|
666
|
+
return false;
|
|
667
|
+
}
|
|
668
|
+
const command = clipboardCommand(platform, env);
|
|
669
|
+
try {
|
|
670
|
+
await execute(command.file, command.args, { cwd, signal, input: text });
|
|
671
|
+
return !signal.aborted;
|
|
672
|
+
}
|
|
673
|
+
catch {
|
|
674
|
+
return false;
|
|
675
|
+
}
|
|
676
|
+
}
|
package/dist/tui.js
ADDED
|
@@ -0,0 +1,420 @@
|
|
|
1
|
+
import { createComponent as _$createComponent } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
2
|
+
import { memo as _$memo } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
3
|
+
import { createTextNode as _$createTextNode } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
4
|
+
import { effect as _$effect } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
5
|
+
import { insertNode as _$insertNode } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
6
|
+
import { insert as _$insert } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
7
|
+
import { setProp as _$setProp } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
8
|
+
import { createElement as _$createElement } from "opentui:runtime-module:%40opentui%2Fsolid";
|
|
9
|
+
/** @jsxImportSource @opentui/solid */
|
|
10
|
+
import { Plugin } from "opentui:runtime-module:%40opencode%2Fplugin%2Ftui";
|
|
11
|
+
import { createMemo, createSignal, onCleanup, onMount, Show } from "opentui:runtime-module:solid-js";
|
|
12
|
+
import { ageOf, checksLineOf, clean, copyToClipboard, createMonitor, MERGE_TONE, openBrowser, summarize } from "./model.js";
|
|
13
|
+
const POLL_MS = 5000;
|
|
14
|
+
function toneColor(theme, tone) {
|
|
15
|
+
if (tone === "success") {
|
|
16
|
+
return theme.text.feedback.success.base;
|
|
17
|
+
}
|
|
18
|
+
if (tone === "error") {
|
|
19
|
+
return theme.text.feedback.error.base;
|
|
20
|
+
}
|
|
21
|
+
if (tone === "warning") {
|
|
22
|
+
return theme.text.feedback.warning.base;
|
|
23
|
+
}
|
|
24
|
+
if (tone === "muted") {
|
|
25
|
+
return theme.text.muted;
|
|
26
|
+
}
|
|
27
|
+
return theme.text.base;
|
|
28
|
+
}
|
|
29
|
+
function lifecycleTone(state) {
|
|
30
|
+
if (state === "MERGED") {
|
|
31
|
+
return "success";
|
|
32
|
+
}
|
|
33
|
+
if (state === "CLOSED") {
|
|
34
|
+
return "error";
|
|
35
|
+
}
|
|
36
|
+
return "base";
|
|
37
|
+
}
|
|
38
|
+
function ActionButton(props) {
|
|
39
|
+
const [over, setOver] = createSignal(false);
|
|
40
|
+
const disabled = () => props.disabled === true;
|
|
41
|
+
const highlighted = () => over() && !disabled();
|
|
42
|
+
return (() => {
|
|
43
|
+
var _el$ = _$createElement("box"),
|
|
44
|
+
_el$2 = _$createElement("text");
|
|
45
|
+
_$insertNode(_el$, _el$2);
|
|
46
|
+
_$setProp(_el$, "height", 1);
|
|
47
|
+
_$setProp(_el$, "flexShrink", 0);
|
|
48
|
+
_$setProp(_el$, "paddingLeft", 1);
|
|
49
|
+
_$setProp(_el$, "paddingRight", 1);
|
|
50
|
+
_$setProp(_el$, "onMouseOver", () => setOver(true));
|
|
51
|
+
_$setProp(_el$, "onMouseOut", () => setOver(false));
|
|
52
|
+
_$setProp(_el$, "onMouseUp", event => {
|
|
53
|
+
if (event.button !== 0 || disabled()) {
|
|
54
|
+
return;
|
|
55
|
+
}
|
|
56
|
+
event.stopPropagation();
|
|
57
|
+
props.onPress();
|
|
58
|
+
});
|
|
59
|
+
_$insert(_el$2, () => props.label);
|
|
60
|
+
_$effect(_p$ => {
|
|
61
|
+
var _v$ = highlighted() ? props.theme.background.raised.high : props.theme.background.raised.base,
|
|
62
|
+
_v$2 = disabled() ? props.theme.text.faint : props.theme.text.base;
|
|
63
|
+
_v$ !== _p$.e && (_p$.e = _$setProp(_el$, "backgroundColor", _v$, _p$.e));
|
|
64
|
+
_v$2 !== _p$.t && (_p$.t = _$setProp(_el$2, "fg", _v$2, _p$.t));
|
|
65
|
+
return _p$;
|
|
66
|
+
}, {
|
|
67
|
+
e: undefined,
|
|
68
|
+
t: undefined
|
|
69
|
+
});
|
|
70
|
+
return _el$;
|
|
71
|
+
})();
|
|
72
|
+
}
|
|
73
|
+
function PrCard(props) {
|
|
74
|
+
// One memoized summary per card: the merge, review, and checks lines share it.
|
|
75
|
+
const summary = createMemo(() => summarize(props.pr));
|
|
76
|
+
return [(() => {
|
|
77
|
+
var _el$3 = _$createElement("box"),
|
|
78
|
+
_el$4 = _$createElement("text"),
|
|
79
|
+
_el$5 = _$createElement("b"),
|
|
80
|
+
_el$6 = _$createTextNode(`#`),
|
|
81
|
+
_el$7 = _$createTextNode(` `),
|
|
82
|
+
_el$8 = _$createElement("a"),
|
|
83
|
+
_el$9 = _$createElement("text"),
|
|
84
|
+
_el$0 = _$createTextNode(` -> `);
|
|
85
|
+
_$insertNode(_el$3, _el$4);
|
|
86
|
+
_$insertNode(_el$3, _el$9);
|
|
87
|
+
_$insertNode(_el$4, _el$5);
|
|
88
|
+
_$insertNode(_el$4, _el$7);
|
|
89
|
+
_$insertNode(_el$4, _el$8);
|
|
90
|
+
_$setProp(_el$4, "onMouseUp", event => {
|
|
91
|
+
if (event.button !== 0) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
event.stopPropagation();
|
|
95
|
+
void props.onOpen();
|
|
96
|
+
});
|
|
97
|
+
_$insertNode(_el$5, _el$6);
|
|
98
|
+
_$insert(_el$5, () => props.pr.number, null);
|
|
99
|
+
_$insert(_el$8, () => clean(props.pr.title));
|
|
100
|
+
_$insertNode(_el$9, _el$0);
|
|
101
|
+
_$insert(_el$9, () => clean(props.pr.headRefName), _el$0);
|
|
102
|
+
_$insert(_el$9, () => clean(props.pr.baseRefName), null);
|
|
103
|
+
_$effect(_p$ => {
|
|
104
|
+
var _v$3 = props.theme.markdown.link,
|
|
105
|
+
_v$4 = props.pr.url,
|
|
106
|
+
_v$5 = props.theme.text.muted;
|
|
107
|
+
_v$3 !== _p$.e && (_p$.e = _$setProp(_el$4, "fg", _v$3, _p$.e));
|
|
108
|
+
_v$4 !== _p$.t && (_p$.t = _$setProp(_el$8, "href", _v$4, _p$.t));
|
|
109
|
+
_v$5 !== _p$.a && (_p$.a = _$setProp(_el$9, "fg", _v$5, _p$.a));
|
|
110
|
+
return _p$;
|
|
111
|
+
}, {
|
|
112
|
+
e: undefined,
|
|
113
|
+
t: undefined,
|
|
114
|
+
a: undefined
|
|
115
|
+
});
|
|
116
|
+
return _el$3;
|
|
117
|
+
})(), (() => {
|
|
118
|
+
var _el$11 = _$createElement("box"),
|
|
119
|
+
_el$12 = _$createElement("text"),
|
|
120
|
+
_el$13 = _$createElement("text"),
|
|
121
|
+
_el$14 = _$createTextNode(`Review: `),
|
|
122
|
+
_el$15 = _$createElement("text"),
|
|
123
|
+
_el$16 = _$createElement("b"),
|
|
124
|
+
_el$17 = _$createElement("text");
|
|
125
|
+
_$insertNode(_el$11, _el$12);
|
|
126
|
+
_$insertNode(_el$11, _el$13);
|
|
127
|
+
_$insertNode(_el$11, _el$15);
|
|
128
|
+
_$insertNode(_el$11, _el$17);
|
|
129
|
+
_$insert(_el$12, () => summary().lifecycle);
|
|
130
|
+
_$insertNode(_el$13, _el$14);
|
|
131
|
+
_$insert(_el$13, () => summary().review, null);
|
|
132
|
+
_$insertNode(_el$15, _el$16);
|
|
133
|
+
_$insert(_el$16, () => summary().merge);
|
|
134
|
+
_$insert(_el$17, () => checksLineOf(summary().checks));
|
|
135
|
+
_$effect(_p$ => {
|
|
136
|
+
var _v$6 = toneColor(props.theme, lifecycleTone(props.pr.state)),
|
|
137
|
+
_v$7 = props.theme.text.muted,
|
|
138
|
+
_v$8 = toneColor(props.theme, MERGE_TONE[summary().merge]),
|
|
139
|
+
_v$9 = summary().checks.failed > 0 ? props.theme.text.feedback.warning.base : props.theme.text.muted;
|
|
140
|
+
_v$6 !== _p$.e && (_p$.e = _$setProp(_el$12, "fg", _v$6, _p$.e));
|
|
141
|
+
_v$7 !== _p$.t && (_p$.t = _$setProp(_el$13, "fg", _v$7, _p$.t));
|
|
142
|
+
_v$8 !== _p$.a && (_p$.a = _$setProp(_el$15, "fg", _v$8, _p$.a));
|
|
143
|
+
_v$9 !== _p$.o && (_p$.o = _$setProp(_el$17, "fg", _v$9, _p$.o));
|
|
144
|
+
return _p$;
|
|
145
|
+
}, {
|
|
146
|
+
e: undefined,
|
|
147
|
+
t: undefined,
|
|
148
|
+
a: undefined,
|
|
149
|
+
o: undefined
|
|
150
|
+
});
|
|
151
|
+
return _el$11;
|
|
152
|
+
})(), (() => {
|
|
153
|
+
var _el$18 = _$createElement("box"),
|
|
154
|
+
_el$19 = _$createElement("text"),
|
|
155
|
+
_el$20 = _$createTextNode(`+`),
|
|
156
|
+
_el$21 = _$createTextNode(` / -`),
|
|
157
|
+
_el$22 = _$createTextNode(` / `),
|
|
158
|
+
_el$24 = _$createTextNode(` files`),
|
|
159
|
+
_el$25 = _$createElement("text"),
|
|
160
|
+
_el$26 = _$createTextNode(` unresolved / `),
|
|
161
|
+
_el$27 = _$createTextNode(` total comments`),
|
|
162
|
+
_el$28 = _$createElement("text"),
|
|
163
|
+
_el$29 = _$createTextNode(`Updated `),
|
|
164
|
+
_el$30 = _$createElement("text");
|
|
165
|
+
_$insertNode(_el$18, _el$19);
|
|
166
|
+
_$insertNode(_el$18, _el$25);
|
|
167
|
+
_$insertNode(_el$18, _el$28);
|
|
168
|
+
_$insertNode(_el$18, _el$30);
|
|
169
|
+
_$insertNode(_el$19, _el$20);
|
|
170
|
+
_$insertNode(_el$19, _el$21);
|
|
171
|
+
_$insertNode(_el$19, _el$22);
|
|
172
|
+
_$insertNode(_el$19, _el$24);
|
|
173
|
+
_$insert(_el$19, () => props.pr.additions.toLocaleString(), _el$21);
|
|
174
|
+
_$insert(_el$19, () => props.pr.deletions.toLocaleString(), _el$22);
|
|
175
|
+
_$insert(_el$19, () => props.pr.changedFiles, _el$24);
|
|
176
|
+
_$insertNode(_el$25, _el$26);
|
|
177
|
+
_$insertNode(_el$25, _el$27);
|
|
178
|
+
_$insert(_el$25, () => props.pr.unresolvedThreads, _el$26);
|
|
179
|
+
_$insert(_el$25, () => props.pr.totalComments, _el$27);
|
|
180
|
+
_$insertNode(_el$28, _el$29);
|
|
181
|
+
_$insert(_el$28, () => ageOf(props.pr.updatedAt, props.now), null);
|
|
182
|
+
_$insert(_el$30, (() => {
|
|
183
|
+
var _c$ = _$memo(() => !!props.loading);
|
|
184
|
+
return () => _c$() ? "Refreshing..." : `Checked ${ageOf(props.fetchedAt, props.now)}`;
|
|
185
|
+
})());
|
|
186
|
+
_$effect(_p$ => {
|
|
187
|
+
var _v$0 = props.theme.text.base,
|
|
188
|
+
_v$1 = props.theme.text.muted,
|
|
189
|
+
_v$10 = props.theme.text.muted,
|
|
190
|
+
_v$11 = props.theme.text.muted;
|
|
191
|
+
_v$0 !== _p$.e && (_p$.e = _$setProp(_el$19, "fg", _v$0, _p$.e));
|
|
192
|
+
_v$1 !== _p$.t && (_p$.t = _$setProp(_el$25, "fg", _v$1, _p$.t));
|
|
193
|
+
_v$10 !== _p$.a && (_p$.a = _$setProp(_el$28, "fg", _v$10, _p$.a));
|
|
194
|
+
_v$11 !== _p$.o && (_p$.o = _$setProp(_el$30, "fg", _v$11, _p$.o));
|
|
195
|
+
return _p$;
|
|
196
|
+
}, {
|
|
197
|
+
e: undefined,
|
|
198
|
+
t: undefined,
|
|
199
|
+
a: undefined,
|
|
200
|
+
o: undefined
|
|
201
|
+
});
|
|
202
|
+
return _el$18;
|
|
203
|
+
})()];
|
|
204
|
+
}
|
|
205
|
+
export default Plugin.define({
|
|
206
|
+
id: "pr-sidebar",
|
|
207
|
+
setup(context) {
|
|
208
|
+
const [state, setState] = createSignal({
|
|
209
|
+
pr: null,
|
|
210
|
+
error: "",
|
|
211
|
+
fetchedAt: 0,
|
|
212
|
+
now: Date.now(),
|
|
213
|
+
loading: false
|
|
214
|
+
});
|
|
215
|
+
const [expanded, setExpanded] = createSignal(true);
|
|
216
|
+
let monitor;
|
|
217
|
+
const lifecycle = new AbortController();
|
|
218
|
+
const directory = () => {
|
|
219
|
+
if (context.location?.directory) {
|
|
220
|
+
return context.location.directory;
|
|
221
|
+
}
|
|
222
|
+
try {
|
|
223
|
+
return context.data.location.default().directory;
|
|
224
|
+
} catch {
|
|
225
|
+
return "";
|
|
226
|
+
}
|
|
227
|
+
};
|
|
228
|
+
// Hide PR data fetched for a previous directory while the monitor catches up.
|
|
229
|
+
const pr = () => state().directory === directory() ? state().pr : null;
|
|
230
|
+
const theme = () => context.theme;
|
|
231
|
+
const toast = (message, variant = "info") => context.ui.toast.show({
|
|
232
|
+
title: "Pull Request",
|
|
233
|
+
message,
|
|
234
|
+
variant
|
|
235
|
+
});
|
|
236
|
+
async function open() {
|
|
237
|
+
const value = pr();
|
|
238
|
+
if (!value) {
|
|
239
|
+
return;
|
|
240
|
+
}
|
|
241
|
+
const message = await openBrowser(value.url, directory(), lifecycle.signal);
|
|
242
|
+
if (message && !lifecycle.signal.aborted) {
|
|
243
|
+
toast(`${message} ${value.url}`, "warning");
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
async function copy() {
|
|
247
|
+
const value = pr();
|
|
248
|
+
if (!value) {
|
|
249
|
+
return;
|
|
250
|
+
}
|
|
251
|
+
const ok = await copyToClipboard(value.url, directory(), lifecycle.signal);
|
|
252
|
+
if (!lifecycle.signal.aborted) {
|
|
253
|
+
toast(ok ? "PR URL copied" : "Could not copy PR URL", ok ? "success" : "error");
|
|
254
|
+
}
|
|
255
|
+
}
|
|
256
|
+
function Card() {
|
|
257
|
+
onMount(() => {
|
|
258
|
+
monitor = createMonitor({
|
|
259
|
+
directory,
|
|
260
|
+
publish: setState
|
|
261
|
+
});
|
|
262
|
+
monitor.tick();
|
|
263
|
+
const timer = setInterval(() => {
|
|
264
|
+
monitor?.tick();
|
|
265
|
+
}, POLL_MS);
|
|
266
|
+
// Never hold the process open on this timer alone; the host owns lifetime.
|
|
267
|
+
timer.unref?.();
|
|
268
|
+
onCleanup(() => clearInterval(timer));
|
|
269
|
+
});
|
|
270
|
+
onCleanup(() => {
|
|
271
|
+
monitor?.stop();
|
|
272
|
+
monitor = undefined;
|
|
273
|
+
});
|
|
274
|
+
// A stable root keeps the slot mounted while the first lookup is in flight.
|
|
275
|
+
return (() => {
|
|
276
|
+
var _el$31 = _$createElement("box"),
|
|
277
|
+
_el$32 = _$createElement("box"),
|
|
278
|
+
_el$33 = _$createElement("text"),
|
|
279
|
+
_el$34 = _$createElement("text"),
|
|
280
|
+
_el$35 = _$createElement("b");
|
|
281
|
+
_$insertNode(_el$31, _el$32);
|
|
282
|
+
_$setProp(_el$31, "gap", 1);
|
|
283
|
+
_$setProp(_el$31, "flexShrink", 0);
|
|
284
|
+
_$insertNode(_el$32, _el$33);
|
|
285
|
+
_$insertNode(_el$32, _el$34);
|
|
286
|
+
_$setProp(_el$32, "flexDirection", "row");
|
|
287
|
+
_$setProp(_el$32, "gap", 1);
|
|
288
|
+
_$setProp(_el$32, "onMouseDown", event => {
|
|
289
|
+
if (event.button !== 0) {
|
|
290
|
+
return;
|
|
291
|
+
}
|
|
292
|
+
event.stopPropagation();
|
|
293
|
+
setExpanded(value => !value);
|
|
294
|
+
});
|
|
295
|
+
_$insert(_el$33, () => expanded() ? "▼" : "▶");
|
|
296
|
+
_$insertNode(_el$34, _el$35);
|
|
297
|
+
_$insertNode(_el$35, _$createTextNode(`Pull Request`));
|
|
298
|
+
_$insert(_el$31, (() => {
|
|
299
|
+
var _c$2 = _$memo(() => !!expanded());
|
|
300
|
+
return () => _c$2() ? [_$createComponent(Show, {
|
|
301
|
+
get when() {
|
|
302
|
+
return pr();
|
|
303
|
+
},
|
|
304
|
+
children: p => _$createComponent(PrCard, {
|
|
305
|
+
get pr() {
|
|
306
|
+
return p();
|
|
307
|
+
},
|
|
308
|
+
get now() {
|
|
309
|
+
return state().now;
|
|
310
|
+
},
|
|
311
|
+
get loading() {
|
|
312
|
+
return state().loading;
|
|
313
|
+
},
|
|
314
|
+
get fetchedAt() {
|
|
315
|
+
return state().fetchedAt;
|
|
316
|
+
},
|
|
317
|
+
get theme() {
|
|
318
|
+
return theme();
|
|
319
|
+
},
|
|
320
|
+
onOpen: open
|
|
321
|
+
})
|
|
322
|
+
}), _$memo(() => _$memo(() => !!state().error)() ? (() => {
|
|
323
|
+
var _el$38 = _$createElement("text");
|
|
324
|
+
_$insert(_el$38, () => pr() ? "STALE: " : "", null);
|
|
325
|
+
_$insert(_el$38, () => state().error, null);
|
|
326
|
+
_$effect(_$p => _$setProp(_el$38, "fg", theme().text.feedback.warning.base, _$p));
|
|
327
|
+
return _el$38;
|
|
328
|
+
})() : null), (() => {
|
|
329
|
+
var _el$37 = _$createElement("box");
|
|
330
|
+
_$setProp(_el$37, "flexDirection", "row");
|
|
331
|
+
_$setProp(_el$37, "gap", 1);
|
|
332
|
+
_$setProp(_el$37, "flexWrap", "wrap");
|
|
333
|
+
_$insert(_el$37, _$createComponent(ActionButton, {
|
|
334
|
+
get label() {
|
|
335
|
+
return state().loading ? "Refreshing" : "Refresh";
|
|
336
|
+
},
|
|
337
|
+
get theme() {
|
|
338
|
+
return theme();
|
|
339
|
+
},
|
|
340
|
+
get disabled() {
|
|
341
|
+
return state().loading;
|
|
342
|
+
},
|
|
343
|
+
onPress: () => monitor?.tick(true)
|
|
344
|
+
}), null);
|
|
345
|
+
_$insert(_el$37, _$createComponent(ActionButton, {
|
|
346
|
+
label: "Copy URL",
|
|
347
|
+
get theme() {
|
|
348
|
+
return theme();
|
|
349
|
+
},
|
|
350
|
+
onPress: () => void copy()
|
|
351
|
+
}), null);
|
|
352
|
+
_$insert(_el$37, _$createComponent(ActionButton, {
|
|
353
|
+
label: "Open",
|
|
354
|
+
get theme() {
|
|
355
|
+
return theme();
|
|
356
|
+
},
|
|
357
|
+
onPress: () => void open()
|
|
358
|
+
}), null);
|
|
359
|
+
return _el$37;
|
|
360
|
+
})()] : null;
|
|
361
|
+
})(), null);
|
|
362
|
+
_$effect(_p$ => {
|
|
363
|
+
var _v$12 = Boolean(pr() || state().error),
|
|
364
|
+
_v$13 = theme().text.base,
|
|
365
|
+
_v$14 = theme().text.base;
|
|
366
|
+
_v$12 !== _p$.e && (_p$.e = _$setProp(_el$31, "visible", _v$12, _p$.e));
|
|
367
|
+
_v$13 !== _p$.t && (_p$.t = _$setProp(_el$33, "fg", _v$13, _p$.t));
|
|
368
|
+
_v$14 !== _p$.a && (_p$.a = _$setProp(_el$34, "fg", _v$14, _p$.a));
|
|
369
|
+
return _p$;
|
|
370
|
+
}, {
|
|
371
|
+
e: undefined,
|
|
372
|
+
t: undefined,
|
|
373
|
+
a: undefined
|
|
374
|
+
});
|
|
375
|
+
return _el$31;
|
|
376
|
+
})();
|
|
377
|
+
}
|
|
378
|
+
context.ui.slot({
|
|
379
|
+
append: "sidebar.content",
|
|
380
|
+
render: () => _$createComponent(Card, {})
|
|
381
|
+
});
|
|
382
|
+
context.keymap.layer(() => ({
|
|
383
|
+
mode: "global",
|
|
384
|
+
priority: 10,
|
|
385
|
+
commands: [{
|
|
386
|
+
id: "pr-sidebar.open",
|
|
387
|
+
title: "PR: Open on GitHub",
|
|
388
|
+
group: "Pull Request",
|
|
389
|
+
palette: true,
|
|
390
|
+
enabled: () => Boolean(pr()),
|
|
391
|
+
run: () => void open()
|
|
392
|
+
}, {
|
|
393
|
+
id: "pr-sidebar.copy",
|
|
394
|
+
title: "PR: Copy URL",
|
|
395
|
+
group: "Pull Request",
|
|
396
|
+
palette: true,
|
|
397
|
+
enabled: () => Boolean(pr()),
|
|
398
|
+
run: () => void copy()
|
|
399
|
+
}, {
|
|
400
|
+
id: "pr-sidebar.refresh",
|
|
401
|
+
title: "PR: Refresh status",
|
|
402
|
+
group: "Pull Request",
|
|
403
|
+
palette: true,
|
|
404
|
+
run: () => monitor?.tick(true)
|
|
405
|
+
}]
|
|
406
|
+
}));
|
|
407
|
+
const offIdle = context.data.on("session.execution.succeeded", () => {
|
|
408
|
+
monitor?.tick(false, true);
|
|
409
|
+
});
|
|
410
|
+
const offBranch = context.data.on("vcs.branch.updated", () => {
|
|
411
|
+
monitor?.tick();
|
|
412
|
+
});
|
|
413
|
+
return () => {
|
|
414
|
+
lifecycle.abort();
|
|
415
|
+
offIdle();
|
|
416
|
+
offBranch();
|
|
417
|
+
monitor?.stop();
|
|
418
|
+
};
|
|
419
|
+
}
|
|
420
|
+
});
|
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,78 @@
|
|
|
1
1
|
{
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
2
|
+
"name": "opencode2-pr-sidebar",
|
|
3
|
+
"version": "0.1.4",
|
|
4
|
+
"private": false,
|
|
5
|
+
"type": "module",
|
|
6
|
+
"description": "Current-branch GitHub PR card for the OpenCode TUI sidebar",
|
|
7
|
+
"keywords": [
|
|
8
|
+
"opencode-plugin",
|
|
9
|
+
"opencode",
|
|
10
|
+
"tui",
|
|
11
|
+
"github",
|
|
12
|
+
"pull-request"
|
|
13
|
+
],
|
|
14
|
+
"homepage": "https://github.com/karczews/opencode-pr-sidebar#readme",
|
|
15
|
+
"bugs": {
|
|
16
|
+
"url": "https://github.com/karczews/opencode-pr-sidebar/issues"
|
|
17
|
+
},
|
|
18
|
+
"license": "MIT",
|
|
19
|
+
"repository": {
|
|
20
|
+
"type": "git",
|
|
21
|
+
"url": "git+https://github.com/karczews/opencode-pr-sidebar.git"
|
|
22
|
+
},
|
|
23
|
+
"exports": {
|
|
24
|
+
"./tui": "./dist/tui.js"
|
|
25
|
+
},
|
|
26
|
+
"files": [
|
|
27
|
+
"dist/tui.js",
|
|
28
|
+
"dist/model.js",
|
|
29
|
+
"docs/assets/card.gif",
|
|
30
|
+
"README.md",
|
|
31
|
+
"LICENSE"
|
|
32
|
+
],
|
|
33
|
+
"engines": {
|
|
34
|
+
"opencode": ">=2.2.6"
|
|
35
|
+
},
|
|
36
|
+
"scripts": {
|
|
37
|
+
"fmt": "biome format --write .",
|
|
38
|
+
"fmt-check": "biome format .",
|
|
39
|
+
"lint": "biome lint .",
|
|
40
|
+
"check:imports": "node scripts/check-imports.mjs",
|
|
41
|
+
"lint:commits": "node scripts/check-commits.mjs",
|
|
42
|
+
"check:audit": "node scripts/check-audit.mjs",
|
|
43
|
+
"typecheck": "tsc --noEmit",
|
|
44
|
+
"test": "node --test test/model.test.ts test/check-imports.test.mjs",
|
|
45
|
+
"test:render": "node --conditions=browser --test test/test-render.test.mjs",
|
|
46
|
+
"check": "npm run fmt-check && npm run lint && npm run check:imports && npm run typecheck && npm run verify:dist && npm test && npm run test:register && npm run test:render",
|
|
47
|
+
"test:register": "node --conditions=browser --test test/tui-register.test.mjs",
|
|
48
|
+
"compile": "node scripts/compile.mjs",
|
|
49
|
+
"verify:dist": "npm run compile && git diff --exit-code -- dist"
|
|
50
|
+
},
|
|
51
|
+
"peerDependencies": {
|
|
52
|
+
"@opentui/core": ">=0.6.6",
|
|
53
|
+
"@opentui/solid": ">=0.6.6",
|
|
54
|
+
"solid-js": ">=1.9.0"
|
|
55
|
+
},
|
|
56
|
+
"peerDependenciesMeta": {
|
|
57
|
+
"@opentui/core": {
|
|
58
|
+
"optional": true
|
|
59
|
+
},
|
|
60
|
+
"@opentui/solid": {
|
|
61
|
+
"optional": true
|
|
62
|
+
},
|
|
63
|
+
"solid-js": {
|
|
64
|
+
"optional": true
|
|
65
|
+
}
|
|
66
|
+
},
|
|
67
|
+
"devDependencies": {
|
|
68
|
+
"@biomejs/biome": "2.6.7",
|
|
69
|
+
"@opencode/client": "2.3.0",
|
|
70
|
+
"@opencode/plugin": "2.3.0",
|
|
71
|
+
"@opencode/theme": "2.3.0",
|
|
72
|
+
"@opentui/core": "0.8.4",
|
|
73
|
+
"@opentui/solid": "0.8.4",
|
|
74
|
+
"@types/node": "26.6.6",
|
|
75
|
+
"solid-js": "1.9.19",
|
|
76
|
+
"typescript": "^7.0.2"
|
|
77
|
+
}
|
|
78
|
+
}
|