Merge indicator

ready…
osebo56d ago

If a diff has been merged, I’d love for the thread indicator “open” to maybe say merged in purple

5 repliesoldestnewest
Osebotfable-5-156d ago

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

  1. Schema — migration 0003: add merged to the thread_status enum and a threads.prs_checked_at timestamp used to throttle GitHub lookups.
  2. Merge check (lib/merge.ts + a pullRequestState helper in lib/agent/github.ts): collect the thread's PRs from post meta (latest per repo alias), ask GitHub GET /repos/:o/:r/pulls/:n with the workspace owner's token, and if all of them are merged → setThreadStatus(id, "merged"). Only threads in open/done are candidates; a PR closed without merge leaves the thread alone.
  3. 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 merged rather than open.
  4. UI — StatusBadge gets .badge.merged: filled GitHub-style purple with white text (new --merged var, 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).

Osebotfable-5-156d ago

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; run npm run db:migrate.
  • lib/merge.ts — syncThreadMergeStatus(threadId, {minAge}) reads the thread's PRs out of post meta (latest per repo alias), hits GET /repos/:o/:r/pulls/:n with the owner token, and sets status = merged when every PR has merged_at. Uses the PR's merge time as updatedAt so list ordering reflects when it actually merged, not when we noticed. Never throws; stamps prs_checked_at even 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), and finishJob right after the status reset — so a re-run on a merged thread that pushed nothing new lands back on merged.
  • lib/agent/github.ts — pullRequestState() helper.
  • CSS: --merged (#8250df light / #8957e5 dark), .badge.merged filled 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.

Osebotfable-5-156d agothreadide@6d55410

Done — 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.

list + thread meta line, light

How it works

  • New thread status merged + threads.prs_checked_at (migration drizzle/0003_thread_merged.sql — run npm run db:migrate on deploy).
  • No webhook needed. lib/merge.ts#syncThreadMergeStatus gathers the thread's PRs from post meta (latest per repo alias), asks GitHub for each PR's merged_at with the workspace owner's token, and sets status = merged when all are merged. If a PR was closed without merging, nothing changes.
  • It runs off the request path with after() from next/server: thread page (re-check at most every minute), home + workspace lists (up to 10 stale threads, every 10 min each), and once inside finishJob after the status reset — so asking Claude a follow-up on a merged thread that produces no new commits lands back on merged, not open. When the flip happens while someone has the thread open, the existing status→pg_notify→SSE→router.refresh() path repaints the badge.
  • Only open/done threads can become merged; running/waiting/failed are more urgent and are left alone. updatedAt is set to the PR's actual merge time so list ordering is honest.
  • prs_checked_at is 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.

Same mockup in dark mode (--merged #8957e5)
Same mockup in dark mode (--merged #8957e5)
oseboasked Osebot56d ago

You can keep it outlined not filled

Osebotfable-5-156d agothreadide@ddce7a2

Done — the merged badge is now outlined, pushed to thread/008bb2e1 (ddce7a2).

Outlined merged badge next to the other statuses — light

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.

Same in dark mode (--merged #8957e5)
Same in dark mode (--merged #8957e5)
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); }