@daoninc/opencode-pr-tracker 0.0.0-stage → 0.1.1

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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Kit Langton
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,54 @@
1
- # Temporary Holding Version
1
+ # PR tracker
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ ## Install
4
+
5
+ Add the fixed `0.1.1` npm release to the existing `plugins`
6
+ array in `~/.config/opencode/cli.json`:
7
+
8
+ ```json
9
+ { "plugins": ["@daoninc/opencode-pr-tracker@0.1.1"] }
10
+ ```
11
+
12
+ Requires OpenCode V2 and a local authenticated GitHub CLI (`gh auth login`). Remove
13
+ the equivalent local entry when switching to npm. Do not enable this port alongside
14
+ the upstream tracker: their functionality overlaps, and published `0.1.0` still
15
+ shares its runtime ID. Version `0.1.1` uses `daoninc.pr-tracker` and ships
16
+ Solid-compiled JavaScript. Do not use the raw-TSX `0.1.0` build with OpenCode 2.3.1.
17
+ This package is TUI-only.
18
+
19
+ ## Attribution and features
20
+
21
+ This TUI-only port is based on `@kitlangton/opencode-pr-tracker` 0.1.1
22
+ ([source](https://github.com/kitlangton/opencode-plugins/tree/dd0de5a31b/packages/pr-tracker))
23
+ and the compatibility changes proposed in
24
+ [upstream PR #5](https://github.com/kitlangton/opencode-plugins/pull/5).
25
+ The upstream code is MIT-licensed; see `LICENSE`.
26
+
27
+ It uses the current OpenCode V2 TUI API and the host's rendering dependencies,
28
+ while retaining 0.1.1's session-scoped `gh pr create` tracking. It also shows
29
+ the PR associated with the active session's checked-out branch, including PRs
30
+ created outside the session, followed by your open PRs in the active repository
31
+ (`gh pr list --author @me --state open`, up to 100). Entries are deduplicated by
32
+ URL, with the current branch and session-created PRs listed first. All sources
33
+ are refreshed every 45 seconds. Closed or merged PRs disappear from the authored
34
+ list on the next successful refresh, but remain visible if tracked by the session
35
+ or current branch. Failed authored-list lookups retain the last successful list;
36
+ switching directories clears it and ignores late results from other directories. GitHub
37
+ lookups use each session's local working directory. `git` and an authenticated
38
+ `gh` CLI are required.
39
+
40
+ This package is maintained separately from upstream. Its version numbers are
41
+ independent. The upstream MIT license and copyright notice are included unchanged
42
+ in every package. Do not configure this plugin in the server's `opencode.json`.
43
+
44
+ The PR tracker icons:
45
+
46
+ | Icon | Meaning | Color |
47
+ |---|---|---|
48
+ | `◇` | Draft PR | Blue |
49
+ | `✓` | Merged | Purple |
50
+ | `×` | Closed, or CI checks failed/cancelled/timed out | Red |
51
+ | `◌` | CI checks pending or running | Yellow |
52
+ | `●` | Open with checks passed, or no checks | Green |
53
+
54
+ Draft status takes priority over the other indicators.
@@ -0,0 +1,4 @@
1
+ export function prUrls(command, output) {
2
+ if (typeof command !== "string" || !/\bgh\s+pr\s+create\b/.test(command) || typeof output !== "string") return [];
3
+ return [...output.matchAll(/https:\/\/github\.com\/[^\s/]+\/[^\s/]+\/pull\/\d+/g)].map(match => match[0]);
4
+ }
package/dist/tui.js ADDED
@@ -0,0 +1,313 @@
1
+ import { createComponent as _$createComponent } from "@opentui/solid";
2
+ import { memo as _$memo } from "@opentui/solid";
3
+ import { effect as _$effect } from "@opentui/solid";
4
+ import { createTextNode as _$createTextNode } from "@opentui/solid";
5
+ import { insertNode as _$insertNode } from "@opentui/solid";
6
+ import { insert as _$insert } from "@opentui/solid";
7
+ import { setProp as _$setProp } from "@opentui/solid";
8
+ import { createElement as _$createElement } from "@opentui/solid";
9
+ import { Plugin } from "@opencode/plugin/tui";
10
+ import { createEffect, createSignal, untrack } from "solid-js";
11
+ import { prUrls } from "./reference.js";
12
+ const POLL_MS = 45_000;
13
+ const COLORS = {
14
+ OPEN: "#a6da95",
15
+ MERGED: "#c6a0f6",
16
+ CLOSED: "#ed8796"
17
+ };
18
+ async function run(cwd, ...command) {
19
+ const proc = Bun.spawn(command, {
20
+ cwd,
21
+ stdout: "pipe",
22
+ stderr: "ignore"
23
+ });
24
+ const stdout = await proc.stdout.text();
25
+ return {
26
+ code: await proc.exited,
27
+ stdout: stdout.trim()
28
+ };
29
+ }
30
+ async function fetchPr(directory, reference) {
31
+ try {
32
+ const result = await run(directory, "gh", "pr", "view", ...(reference ? [reference] : []), "--json", "number,url,state,title,isDraft,mergedAt,statusCheckRollup");
33
+ if (result.code !== 0) return undefined;
34
+ const parsed = JSON.parse(result.stdout);
35
+ if (typeof parsed !== "object" || parsed === null) return undefined;
36
+ const pr = parsed;
37
+ return typeof pr.number === "number" && typeof pr.url === "string" ? pr : undefined;
38
+ } catch {
39
+ return undefined;
40
+ }
41
+ }
42
+ async function fetchAuthoredPrs(directory) {
43
+ try {
44
+ const result = await run(directory, "gh", "pr", "list", "--author", "@me", "--state", "open", "--limit", "100", "--json", "number,url,state,title,isDraft,mergedAt,statusCheckRollup");
45
+ if (result.code !== 0) return undefined;
46
+ const parsed = JSON.parse(result.stdout);
47
+ if (!Array.isArray(parsed)) return undefined;
48
+ return parsed.filter(pr => typeof pr === "object" && pr !== null && typeof pr.number === "number" && typeof pr.url === "string");
49
+ } catch {
50
+ return undefined;
51
+ }
52
+ }
53
+ function inputCommand(input) {
54
+ return typeof input === "object" && input !== null && !Array.isArray(input) && "command" in input ? input.command : undefined;
55
+ }
56
+ function createdPrUrls(messages) {
57
+ const urls = new Set();
58
+ const adopt = (command, output) => prUrls(command, output).forEach(url => urls.add(url));
59
+ for (const message of messages) {
60
+ if (message.type === "shell") {
61
+ if (message.status === "exited" && message.exit === 0) adopt(message.command, message.output?.output);
62
+ continue;
63
+ }
64
+ if (message.type !== "assistant") continue;
65
+ for (const part of message.content) {
66
+ if (part.type !== "tool" || part.state.status !== "completed") continue;
67
+ adopt(inputCommand(part.state.input), part.state.content.filter(item => item.type === "text").map(item => item.text).join("\n"));
68
+ }
69
+ }
70
+ return [...urls];
71
+ }
72
+ function checkStatus(pr) {
73
+ const checks = (pr.statusCheckRollup ?? []).filter(check => check.conclusion !== "SKIPPED");
74
+ if (checks.some(check => check.status && check.status !== "COMPLETED")) return "pending";
75
+ if (checks.some(check => ["FAILURE", "TIMED_OUT", "CANCELLED", "ACTION_REQUIRED", "STARTUP_FAILURE", "STALE"].includes(check.conclusion ?? ""))) return "failed";
76
+ return checks.length > 0 ? "passed" : "none";
77
+ }
78
+ function statusIcon(pr) {
79
+ if (pr.isDraft) return "◇";
80
+ if (pr.state === "MERGED") return "✓";
81
+ if (pr.state === "CLOSED") return "×";
82
+ const checks = checkStatus(pr);
83
+ if (checks === "pending") return "◌";
84
+ if (checks === "failed") return "×";
85
+ return "●";
86
+ }
87
+ function statusColor(pr) {
88
+ if (pr.isDraft) return "#8aadf4";
89
+ if (pr.state === "MERGED") return COLORS.MERGED;
90
+ const checks = checkStatus(pr);
91
+ if (pr.state === "CLOSED" || checks === "failed") return COLORS.CLOSED;
92
+ if (checks === "pending") return "#eed49f";
93
+ return COLORS.OPEN;
94
+ }
95
+ function changed(left, right) {
96
+ return JSON.stringify(left) !== JSON.stringify(right);
97
+ }
98
+ function PrRow(props) {
99
+ const [hovered, setHovered] = createSignal(false);
100
+ return (() => {
101
+ var _el$ = _$createElement("box"),
102
+ _el$2 = _$createElement("text"),
103
+ _el$3 = _$createElement("text"),
104
+ _el$4 = _$createElement("span"),
105
+ _el$5 = _$createTextNode(`#`),
106
+ _el$6 = _$createTextNode(` `);
107
+ _$insertNode(_el$, _el$2);
108
+ _$insertNode(_el$, _el$3);
109
+ _$setProp(_el$, "flexDirection", "row");
110
+ _$setProp(_el$, "gap", 1);
111
+ _$setProp(_el$, "onMouseOver", () => setHovered(true));
112
+ _$setProp(_el$, "onMouseOut", () => setHovered(false));
113
+ _$setProp(_el$, "onMouseUp", () => Bun.spawn(["open", props.pr.url]));
114
+ _$setProp(_el$2, "flexShrink", 0);
115
+ _$insert(_el$2, () => statusIcon(props.pr));
116
+ _$insertNode(_el$3, _el$4);
117
+ _$insertNode(_el$3, _el$6);
118
+ _$setProp(_el$3, "wrapMode", "word");
119
+ _$insertNode(_el$4, _el$5);
120
+ _$insert(_el$4, () => props.pr.number, null);
121
+ _$insert(_el$3, () => props.pr.title, null);
122
+ _$effect(_p$ => {
123
+ var _v$ = hovered() ? props.context.theme.background.action.primary.hovered : undefined,
124
+ _v$2 = statusColor(props.pr),
125
+ _v$3 = props.context.theme.text.base,
126
+ _v$4 = {
127
+ fg: hovered() ? props.context.theme.text.base : props.context.theme.text.muted
128
+ };
129
+ _v$ !== _p$.e && (_p$.e = _$setProp(_el$, "backgroundColor", _v$, _p$.e));
130
+ _v$2 !== _p$.t && (_p$.t = _$setProp(_el$2, "fg", _v$2, _p$.t));
131
+ _v$3 !== _p$.a && (_p$.a = _$setProp(_el$3, "fg", _v$3, _p$.a));
132
+ _v$4 !== _p$.o && (_p$.o = _$setProp(_el$4, "style", _v$4, _p$.o));
133
+ return _p$;
134
+ }, {
135
+ e: undefined,
136
+ t: undefined,
137
+ a: undefined,
138
+ o: undefined
139
+ });
140
+ return _el$;
141
+ })();
142
+ }
143
+ export default Plugin.define({
144
+ id: "daoninc.pr-tracker",
145
+ setup: async context => {
146
+ const location = context.location ?? context.data.location.default();
147
+ const sessionDirectory = sessionID => context.data.session.get(sessionID)?.location.directory ?? location.directory;
148
+ const [state, update] = context.storage.memory("pr-sidebar-v2", {
149
+ initial: {
150
+ roots: {},
151
+ prs: {},
152
+ directories: {}
153
+ }
154
+ });
155
+ const recovered = new Set();
156
+ const branchLookups = new Set();
157
+ const authoredLookups = new Set();
158
+ const [branchPr, setBranchPr] = createSignal();
159
+ const [authoredPrs, setAuthoredPrs] = createSignal();
160
+ let activeRoot = "";
161
+ let activeDirectory = "";
162
+ let disposed = false;
163
+ let inFlight = false;
164
+ const adopt = async (sessionID, urls, directory = sessionDirectory(sessionID)) => {
165
+ if (disposed || urls.length === 0) return;
166
+ const root = context.data.session.root(sessionID);
167
+ const previous = state.roots[root] ?? [];
168
+ const next = [...new Set([...previous, ...urls])];
169
+ if (next.length !== previous.length || urls.some(url => state.directories?.[url] !== directory)) update(draft => {
170
+ draft.roots[root] = next;
171
+ draft.directories ??= {};
172
+ for (const url of urls) draft.directories[url] = directory;
173
+ });
174
+ const missing = urls.filter(url => !state.prs[url]);
175
+ const prs = (await Promise.all(missing.map(url => fetchPr(directory, url)))).filter(pr => pr !== undefined);
176
+ if (disposed || prs.length === 0) return;
177
+ if (prs.some(pr => changed(state.prs[pr.url], pr))) update(draft => {
178
+ for (const pr of prs) draft.prs[pr.url] = pr;
179
+ });
180
+ };
181
+ const recover = sessionID => {
182
+ const root = context.data.session.root(sessionID);
183
+ if (recovered.has(root)) return;
184
+ recovered.add(root);
185
+ for (const member of new Set([root, ...context.data.session.family(root)])) void adopt(member, createdPrUrls(context.data.session.message.list(member)));
186
+ };
187
+ const refreshBranch = async () => {
188
+ const directory = activeDirectory;
189
+ if (disposed || !directory || branchLookups.has(directory)) return;
190
+ branchLookups.add(directory);
191
+ try {
192
+ const pr = await fetchPr(directory);
193
+ if (disposed || activeDirectory !== directory) return;
194
+ const previous = branchPr();
195
+ if (!pr) {
196
+ if (previous?.directory === directory) setBranchPr(undefined);
197
+ } else if (previous?.directory !== directory || changed(previous.pr, pr)) {
198
+ setBranchPr({
199
+ directory,
200
+ pr
201
+ });
202
+ }
203
+ } finally {
204
+ branchLookups.delete(directory);
205
+ }
206
+ };
207
+ const refreshAuthored = async () => {
208
+ const directory = activeDirectory;
209
+ if (disposed || !directory || authoredLookups.has(directory)) return;
210
+ authoredLookups.add(directory);
211
+ try {
212
+ const prs = await fetchAuthoredPrs(directory);
213
+ if (disposed || activeDirectory !== directory || !prs) return;
214
+ const previous = authoredPrs();
215
+ if (previous?.directory !== directory || JSON.stringify(previous.prs) !== JSON.stringify(prs)) setAuthoredPrs({
216
+ directory,
217
+ prs
218
+ });
219
+ } finally {
220
+ authoredLookups.delete(directory);
221
+ }
222
+ };
223
+ const refresh = async () => {
224
+ if (disposed || inFlight) return;
225
+ inFlight = true;
226
+ try {
227
+ const urls = state.roots[activeRoot] ?? [];
228
+ const prs = (await Promise.all(urls.map(url => fetchPr(state.directories?.[url] ?? sessionDirectory(activeRoot), url)))).filter(pr => pr !== undefined);
229
+ if (disposed || !prs.some(pr => changed(state.prs[pr.url], pr))) return;
230
+ update(draft => {
231
+ for (const pr of prs) draft.prs[pr.url] = pr;
232
+ });
233
+ } finally {
234
+ inFlight = false;
235
+ }
236
+ };
237
+ const timer = setInterval(() => {
238
+ void refreshBranch();
239
+ void refreshAuthored();
240
+ void refresh();
241
+ }, POLL_MS);
242
+ const unsubscribers = [context.data.on("session.shell.ended", event => {
243
+ if (event.data.shell.status !== "exited" || event.data.shell.exit !== 0) return;
244
+ void adopt(event.data.sessionID, prUrls(event.data.shell.command, event.data.output.output), event.location?.directory);
245
+ }), context.data.on("session.tool.success", event => {
246
+ const message = context.data.session.message.get(event.data.sessionID, event.data.assistantMessageID);
247
+ if (message?.type !== "assistant") return;
248
+ const part = message.content.find(item => item.type === "tool" && item.id === event.data.id);
249
+ if (part?.type !== "tool" || part.state.status !== "completed") return;
250
+ void adopt(event.data.sessionID, prUrls(inputCommand(part.state.input), event.data.content.filter(item => item.type === "text").map(item => item.text).join("\n")), event.location?.directory);
251
+ })];
252
+ context.ui.slot({
253
+ append: "sidebar.content",
254
+ render: props => {
255
+ const root = () => context.data.session.root(props.sessionID);
256
+ createEffect(() => {
257
+ const sessionID = props.sessionID;
258
+ const nextRoot = root();
259
+ const directory = sessionDirectory(sessionID);
260
+ const changedContext = activeRoot !== nextRoot || activeDirectory !== directory;
261
+ if (activeDirectory !== directory) {
262
+ setBranchPr(undefined);
263
+ setAuthoredPrs(undefined);
264
+ }
265
+ activeRoot = nextRoot;
266
+ activeDirectory = directory;
267
+ untrack(() => {
268
+ recover(sessionID);
269
+ if (changedContext) {
270
+ void refreshBranch();
271
+ void refreshAuthored();
272
+ void refresh();
273
+ }
274
+ });
275
+ });
276
+ const list = () => {
277
+ const urls = state.roots[root()] ?? [];
278
+ const prs = new Map();
279
+ const current = branchPr();
280
+ if (current?.directory === sessionDirectory(props.sessionID)) prs.set(current.pr.url, current.pr);
281
+ for (const url of urls) {
282
+ const pr = state.prs[url];
283
+ if (pr && !prs.has(url)) prs.set(url, pr);
284
+ }
285
+ const authored = authoredPrs();
286
+ if (authored?.directory === sessionDirectory(props.sessionID)) for (const pr of authored.prs) {
287
+ if (!prs.has(pr.url)) prs.set(pr.url, pr);
288
+ }
289
+ return [...prs.values()];
290
+ };
291
+ return _$memo(() => _$memo(() => list().length > 0)() ? (() => {
292
+ var _el$7 = _$createElement("box"),
293
+ _el$8 = _$createElement("text"),
294
+ _el$9 = _$createElement("b");
295
+ _$insertNode(_el$7, _el$8);
296
+ _$insertNode(_el$8, _el$9);
297
+ _$insertNode(_el$9, _$createTextNode(`Pull requests`));
298
+ _$insert(_el$7, () => list().map(pr => _$createComponent(PrRow, {
299
+ context: context,
300
+ pr: pr
301
+ })), null);
302
+ _$effect(_$p => _$setProp(_el$8, "fg", context.theme.text.base, _$p));
303
+ return _el$7;
304
+ })() : undefined);
305
+ }
306
+ });
307
+ return () => {
308
+ disposed = true;
309
+ for (const unsubscribe of unsubscribers) unsubscribe();
310
+ clearInterval(timer);
311
+ };
312
+ }
313
+ });
package/package.json CHANGED
@@ -1,6 +1,15 @@
1
1
  {
2
2
  "name": "@daoninc/opencode-pr-tracker",
3
- "version": "0.0.0-stage",
4
- "stub": true,
5
- "description": "Temporary package placeholder for staged publishing"
6
- }
3
+ "version": "0.1.1",
4
+ "description": "OpenCode V2 port of Kit Langton's PR tracker with branch and authored pull requests",
5
+ "type": "module",
6
+ "license": "MIT",
7
+ "exports": { "./tui": "./dist/tui.js" },
8
+ "files": ["dist", "README.md", "LICENSE"],
9
+ "scripts": { "test": "bun test", "prepack": "bun run ../../scripts/build.ts .", "prepublishOnly": "bun run ../../scripts/build.ts . && bun run ../../scripts/check-release.ts ." },
10
+ "dependencies": { "@opencode/plugin": "^2.3.1" },
11
+ "peerDependencies": { "@opentui/core": ">=0.8.4 <0.9", "@opentui/solid": ">=0.8.4 <0.9", "solid-js": "^1.9.0" },
12
+ "publishConfig": { "access": "public", "registry": "https://registry.npmjs.org/" },
13
+ "keywords": ["opencode", "opencode-plugin", "tui", "github", "pull-requests"],
14
+ "repository": { "type": "git", "url": "git+https://github.com/daon-private/sdk-tools.git", "directory": "AI/opencode/plugins/pr-tracker" }
15
+ }