If a diff has been merged, I’d love for the thread indicator “open” to maybe say merged in purple
Merge indicator
Goal: when every PR a thread opened has been merged on GitHub, the thread's status badge shows merged in purple instead of "open" — on the thread page and in the thread lists.
How the pieces fit today: PRs are opened at run-finish (lib/agent/finish.ts → ensurePullRequest) and their {url, number} are stored per repo alias in the done post's meta.prs. Nothing ever looks at the PR again, and there's no GitHub webhook infrastructure — so "merged" has to be discovered by asking GitHub.
Plan
- Schema — migration
0003: addmergedto thethread_statusenum and athreads.prs_checked_attimestamp used to throttle GitHub lookups. - Merge check (
lib/merge.ts+ apullRequestStatehelper inlib/agent/github.ts): collect the thread's PRs from post meta (latest per repo alias), ask GitHubGET /repos/:o/:r/pulls/:nwith the workspace owner's token, and if all of them are merged →setThreadStatus(id, "merged"). Only threads inopen/doneare candidates; a PR closed without merge leaves the thread alone. - When it runs — no cron/webhook needed:
- thread page: kick off a check for that thread (throttled to once a minute) in Next's
after(), so it adds no latency; the existing status→pg_notify→SSE→router.refresh()path repaints the badge when it flips. - home/workspace lists: same, for up to ~10 stale candidate threads per load (throttled per thread to 10 min).
- run finish: re-check immediately after PRs are (re)opened, so a merged thread that gets a follow-up run without new commits goes straight back to
mergedrather thanopen.
- thread page: kick off a check for that thread (throttled to once a minute) in Next's
- UI —
StatusBadgegets.badge.merged: filled GitHub-style purple with white text (new--mergedvar, light + dark values). No label mapping needed ("merged" reads fine).
I'll verify with tsc --noEmit and a static CSS mockup screenshot (the app itself needs Postgres + OAuth, which the sandbox doesn't have).
Implementation is in and tsc --noEmit is clean. What landed:
drizzle/0003_thread_merged.sql—ALTER TYPE thread_status ADD VALUE 'merged'+threads.prs_checked_at(throttle stamp). Journal updated; runnpm run db:migrate.lib/merge.ts—syncThreadMergeStatus(threadId, {minAge})reads the thread's PRs out of post meta (latest per repo alias), hitsGET /repos/:o/:r/pulls/:nwith the owner token, and setsstatus = mergedwhen every PR hasmerged_at. Uses the PR's merge time asupdatedAtso list ordering reflects when it actually merged, not when we noticed. Never throws; stampsprs_checked_ateven on failure so a bad token doesn't retry every view.syncStaleThreads(rows)runs it for ≤10 stale candidates.- Hooks: thread page (
after(), 1-min throttle), home + workspace lists (after(), 10-min throttle), andfinishJobright after the status reset — so a re-run on a merged thread that pushed nothing new lands back onmerged. lib/agent/github.ts—pullRequestState()helper.- CSS:
--merged(#8250df light / #8957e5 dark),.badge.mergedfilled purple, white text.
Only open/done threads can flip to merged; running/waiting/failed are left alone since they say something more urgent. Now doing a mockup screenshot of the badge.
threadide@6d55410Done — pushed to thread/008bb2e1 (6d55410). Once every PR a thread opened has been merged on GitHub, its status badge reads merged in purple, in the thread lists and on the thread page.
How it works
- New thread status
merged+threads.prs_checked_at(migrationdrizzle/0003_thread_merged.sql— runnpm run db:migrateon deploy). - No webhook needed.
lib/merge.ts#syncThreadMergeStatusgathers the thread's PRs from post meta (latest per repo alias), asks GitHub for each PR'smerged_atwith the workspace owner's token, and setsstatus = mergedwhen all are merged. If a PR was closed without merging, nothing changes. - It runs off the request path with
after()fromnext/server: thread page (re-check at most every minute), home + workspace lists (up to 10 stale threads, every 10 min each), and once insidefinishJobafter the status reset — so asking Claude a follow-up on a merged thread that produces no new commits lands back onmerged, notopen. When the flip happens while someone has the thread open, the existing status→pg_notify→SSE→router.refresh()path repaints the badge. - Only
open/donethreads can becomemerged;running/waiting/failedare more urgent and are left alone.updatedAtis set to the PR's actual merge time so list ordering is honest. prs_checked_atis stamped even when GitHub errors (bad token, deleted repo), so a broken thread doesn't retry on every view — it just logs[merge] check skipped.
UI: --merged var (#8250df light / #8957e5 dark), .badge.merged filled with white text, mirroring GitHub's own "Merged" pill. StatusBadge needed no code change.
Caveats: the GitHub calls are unverified against a live account (sandbox has no DB/OAuth) — the mockup above links the real stylesheet but the flow itself should be sanity-checked on a real merged thread after migrating. Rate-limit cost is ≤1 call per PR per thread per throttle window, well under the 5000/h user-token budget.
You can keep it outlined not filled
threadide@ddce7a2Done — the merged badge is now outlined, pushed to thread/008bb2e1 (ddce7a2).
One-line CSS change in app/globals.css: .badge.merged is purple border + purple text on the card background, no fill — the same treatment as the waiting (amber) and failed (red) badges. done stays the only filled badge. The --merged var (#8250df light / #8957e5 dark) is unchanged; dark-mode shot attached too.
Everything else from the previous post (migration 0003, lib/merge.ts sync, after() hooks) is untouched — still run npm run db:migrate on deploy.
Diff · 1 files
--- a/threadide/app/globals.css
+++ b/threadide/app/globals.css
@@ -159,5 +159,5 @@
-/* Every PR the thread opened has merged. Filled like GitHub's own "Merged" pill; white text reads on both purples. */
-.badge.merged { border-color: var(--merged); color: #fff; background: var(--merged); }
+/* Every PR the thread opened has merged. Outlined like the other status badges (waiting/failed), just in purple. */
+.badge.merged { border-color: var(--merged); color: var(--merged); }


