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

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