Forge integration that creates a pull request or merge request from a DSH thread, links it to the thread, watches it, and reports meaningful state changes through the thread sidebar. GitHub uses gh; GitLab uses glab behind the same forge port (src/forge-port.ts), so link, watch, create and the composer # picker work on both. In the browser, the command palette's Create pull request from this thread opens a dialog: it previews the repository, bookmark, base and commits, shows a title and body drafted from the thread that you can edit, lists every blocker with its fix, and pushes and creates only when you confirm. The result links the pull request to the thread and starts watching it. The plugin exposes these Agent tools:
pull_request_link— link by GitHub PR URL or GitLab merge-request URL, or by number and repositorycwd.pull_request_unlink— remove one link by URL or repository plus number.pull_request_list— list one thread's links, or all links withall: true; includes last known state and watch status.pull_request_watch/pull_request_unwatch— start or stop watching; watch creates the link if needed, unwatch keeps it.pull_request_create_preview— read-only preview of opening a PR from a thread's jj workspace: repository, base branch, bookmark, the commits above<base>@<remote>, a title and body drafted from the thread, an open PR that already uses the bookmark, and every blocking problem with its recovery.pull_request_create— after the preview, withconfirm: trueand the preview'sheadCommitId: sets the bookmark on that commit, runsjj git push --remote <remote> --bookmark <name>, thengh pr create(or reuses the open PR for the bookmark), and links and watches the PR on the thread.
Two ways in, one dialog: the palette's Create pull request, and Open PR beside Land on the Changes facet's
Land card (diffs-review), which this plugin adds through diffs-review's
land-card-actions registry (this plugin depends on diffs-review, never the reverse). Both open the preview below and
publish only from its confirm button. Once a pull request is linked to the thread, the card shows #N, its state and
its CI checks ("1 of 4 checks failed" in the failure colour) instead of the button, read from the links this plugin
already watches; the agent reads the same with pull_request_list.
The preview changes nothing. It reads the thread's directory from its stored header and its title from the title index; only when the model drafts the description does it read the conversation (a bounded window of the newest messages and the last model route). It runs gh auth status, gh repo view and gh pr list --head, and reads jj: the remote (origin first), the base branch (gh's default branch at that remote), and the commits from <base>@<remote> to the working copy (an empty, undescribed working-copy commit is skipped). The bookmark is an existing local bookmark on the head commit, else dsh/<thread-title-slug>.
The title and body come from one model call on the thread's own route (or a passed provider/model). Without a model service, a route or a usable answer, the draft falls back to the commit messages and generation.note says why.
Create reads only the thread's directory (none at all when cwd is passed), never its conversation. It re-checks everything and refuses when the workspace head is no longer the previewed commit, so a confirmed preview is exactly what is pushed. Every blocker carries a recovery:
| Problem | Recovery offered |
|---|---|
| gh missing / not signed in / no GitHub repository | install gh, gh auth login, or add the GitHub remote |
| jj missing / not a jj workspace / no remote / base not fetched | install jj, run from a jj workspace, jj git remote add, jj git fetch |
| no commits, undescribed or conflicted commits | commit the work, jj describe or jj abandon the empty one, jj resolve |
| bookmark points elsewhere, push rejected | choose another name or --allow-backwards; fetch and rebase, or fix Git credentials |
gh pr create failed after the push |
the branch is pushed; retry, or open it on GitHub and pull_request_link it |
sessionId defaults to the calling thread. URL links use the Agent's current cwd when available; number links require cwd so gh repo view can identify the repository. An empty stored cwd means no calling directory was available; polling still uses --repo explicitly.
- Uses the installed
gh(GitHub) orglab(GitLab) executable and its existing login. It never reads, prints, or stores an authentication token. GitHub Enterprise hosts are not supported: a host whose name containsgithub(other than github.com) is refused, and any other https host is treated as GitLab. - GitLab: a bare
owner/namerepository key is GitHub (the same keys older records hold), and a dotted first segment names a forge host (gitlab.com/group/sub/project). Repository and merge-request URLs are parsed strictly (https only, no userinfo,/-/merge_requests/<n>); other hosts are refused with a message naming the supported forges.glab mr view --output jsonis decoded into the same normalized view the GitHub watcher stores:detailed_merge_status/merge_statusmap mergeability,blocking_discussions_resolvedand conflicts map to BLOCKED,head_pipeline.statusbecomes onepipelinecheck entry, and the review decision stays unknown (null): the payload carries the approval rule (approvals_required), not whether it is met.glab mr create --yescreates the merge request; the push is the samejj git pushas GitHub. - Verify GitLab on a host with
glabinstalled:glab auth status, thenpnpm --dir plugins/@dshfiles/pull-requests testcovers parsing and normalization, andlink/watchneed a real merge-request URL. - Typing
#in the composer lists recent GitHub issues and pull requests of the thread's repository. Whenghis missing or signed out, the list shows one recovery row instead (“Sign in with gh auth login to list issues”); choosing it copies the command (or the install link) and inserts nothing. A folder with no GitHub remote is not a forge, so the list stays empty there.pull_request_searchreports the same reason to the agent. - Watching polls immediately. After that, Host events refresh a thread's watched pull requests within a debounce (3 seconds by default): a
jj git push,git push,gh pr create|merge|ready|close|reopenorglab mr …command returning in that thread, the end of one of its turns, or a new link to a pull request that another thread watches. A pull request checked in the last 20 seconds is skipped, so a push and the turn end after it cost one read. A slow sweep polls every watched pull request every ten minutes by default as the fallback for changes made outside DSH. Multiple linked threads and backlog items watching the same repository and PR share one read per poll; every GitHub pull request of one pass is read in batched GraphQL calls (see GitHub API budget). Links, last-known state, and rate-limit backoff persist in the HostStorageDomain. - Measured by the probe in
tests/refresh-triggers.spec.ts(five watched pull requests, one hour, two pushes): the former two-minute sweep made 150gh pr viewcalls and saw a push up to two minutes late; the event-driven watcher makes 32 and sees each push within the 3-second debounce. - Settings (namespace
dshfiles-pull-requests, applied live):refreshOnThreadEvents(default on; off leaves only the sweep),eventDebounceSeconds(default 3, 1–60),sweepMinutes(default 10, 1–120; lower it when event refresh is off),githubPointsFloor(default 500, 0–4,900; see below). Each burst and each sweep reads them again, so a change applies without a restart; a Host older than this namespace runs on these defaults. - A full read takes
state,mergeable,mergeStateStatus,reviewDecision, the head commit's check rollup (up to 100 checks), the latest 20 comments and reviews with their totals, andbody. New comment/review messages contain only author and timestamp, not user-authored text. The first 16,384 characters of the description are kept with the last known state, so another plugin can read the closing references it names (Closes b:k3f9); a stored record written before that field simply has no description. - GitHub's status rollup does not separately identify required versus optional checks. The “checks passed” transition is therefore conservative: GitHub must report
mergeStateStatus: CLEAN, at least one status entry must be present, and every returned entry must be successful. It does not claim a separately enumerated branch-protection check set. - A rate-limit error applies persisted exponential backoff starting at two minutes and capped at one hour, and stops the remaining batches of that pass. Other CLI or schema failures retain the last known state and retry on a later cycle; a pull request GitHub cannot answer (deleted, no access) fails alone while the rest of its batch still reads.
- On merge or close, watching stops after that one read, and the plugin asks
thread-sidebarto settle the linked thread. Auto-settle can skip running, waiting, blank, archived, pinned, opted-out, or descendant-active threads. Whenthread-sidebaris loaded but the settle request fails, the link keeps watching and the next poll asks again; once it is settled (or whenthread-sidebaris absent and nothing can settle it) the terminal pull request is never polled again. Ifthread-sidebaris absent, the Host logs that message/settle integration was unavailable.
GitHub gives each account 5,000 GraphQL points an hour, shared with every gh call agents make. The watcher spends as
little of it as it can:
- Batched reads. One
gh api graphqlcall reads up to fifty pull requests with aliases (p0: repository(…){pullRequest(number:…){…}}), and the same query asks forrateLimit { cost remaining resetAt }. - Fingerprint pass. A pull request whose stored snapshot has a fingerprint is first read cheaply:
state,updatedAt,mergeable,mergeStateStatus,reviewDecision, the head commitoid, its rollup state and its check counts by state. The digest of those fields is stored with the snapshot; when it still matches, nothing else is read and no transition can have happened. Check runs do not moveupdatedAt, so the head commit and check counts are part of the digest. Only the pull requests whose digest changed get the full read. - Budget floor. When a read reports fewer than
githubPointsFloorpoints remaining (default 500), GitHub reads wait until the reportedresetAt. An explicitpull_request_watchstill reads once.0never waits. - Terminal pull requests stop after the read that saw them merge or close (above).
Measured by tests/gh-call-budget.spec.ts: a stub gh counts processes and charges points with GitHub's formula (requests each connection needs, summed, divided by 100, at least 1). GitHub charged the same costs live, for read-only queries against cli/cli on 2026-11-11: gh pr view = one query = 1 point; fifty aliases full = 2 points (71 KB), fifty aliases fingerprint = 1 point (11 KB).
| Watched pull requests | Before, per sweep (gh pr view each) |
After, first sweep (full) | After, quiet sweep (fingerprint) | Before → after per hour at the 10 min sweep |
|---|---|---|---|---|
| 5 | 5 spawns, 5 points | 1 spawn, 1 point | 1 spawn, 1 point | 30 → 6 spawns, 30 → 6 points |
| 50 | 50 spawns, 50 points | 1 spawn, 2 points | 1 spawn, 1 point | 300 → 6 spawns, 300 → 6 points |
| 300 | 300 spawns, 300 points | 6 spawns, 12 points | 6 spawns, 6 points | 1,800 → 36 spawns, 1,800 → 36 points |
A pull request that changed between sweeps adds one full read to its batch (one more spawn, 1–2 points per fifty). Event refreshes cost the same per batch as a sweep; the 20-second minimum age still applies.
Polling stays the only refresh path. A GitHub repository webhook could push refreshes instead of waiting for the sweep,
but only when GitHub can reach the Host: the DSH web server listens on a local address, so it needs a public URL or a
tunnel (cloudflared tunnel, tailscale funnel, ngrok). With one:
@dshfiles/project-automationsalready serves signed webhooks atPOST /automations/webhook/<id>and verifies GitHub'sx-hub-signature-256against asecret:ALIAS(its README covers limits and replay handling). Today such an automation starts a thread with a prompt; it does not refresh a watched pull request.- The wiring, proposed and not built: subscribe the repository webhook to
pull_request,pull_request_review,check_suiteandissue_comment(issuesonly matters to the backlog's issue states); map each delivery torepository.full_namepluspull_request.number(orcheck_suite.pull_requests[].number, orissue.numberwhenissue.pull_requestis set); refresh only pull requests already watched, through the same debounced batch read. Unknown pull requests are ignored, so a delivery can never add a watch. - It stays off by default and needs a secret reference setting plus the credential-port and web-server dependencies in this plugin. Batching and the fingerprint pass already cut a 300-watch hour to 36 points, so the webhook would buy latency, not budget.
The published contract (@dshfiles/pull-requests/api) also serves Host plugins that keep forge state for something other than a thread. They are Host API methods, not Agent tools: the backlog decides what to watch.
watchFor({ owner: { kind: 'backlog-item', id }, url, cwd? })watches a pull request or merge request for that owner. It is stored in its ownownedtable of the same storage domain (a domain stored before it opens with the table empty), polled by the same sweep and in the same batched read as the thread links of that pull request, and never prompts or settles a thread. A new watch polls at once unless a rate-limit backoff holds; then the sweep picks it up. Idempotent; a watch on a merged or closed pull request keeps its terminal state and is not polled again.unwatchFor({ owner, url? })releases one watch, or all of an owner's;ownedWatches({ kind })lists them with each last known state andlastCheckedAt.issueStates({ urls })reads up to 100 GitHub issues, fifty pergh api graphqlcall (stateandstateReasononly). An issue gh cannot answer (deleted, transferred) comes back infailedwhile the rest of its batch still reads; a rate limit stops the remaining batches and answersrateLimited: true, so the caller backs off. Nothing is stored here: the caller keeps what it read.- The backlog uses both: each open item watches the pull requests it links and reads its linked issues on its own
revisionPollMinutespass (see the backlog README).
From the repository root:
pnpm --dir plugins/@dshfiles/pull-requests test
pnpm --dir plugins/@dshfiles/pull-requests typecheck
pnpm --dir plugins/@dshfiles/pull-requests lint
pnpm exec turbo run build --filter=@dshfiles/pull-requests
node plugins/@dshfiles/pull-requests/scripts/host-import-check.mjstests/create-host.spec.ts creates a PR end to end against a real test Host, real jj and a temporary bare Git remote, with a shell-script gh on PATH, and checks the pushed branch, the gh pr create argv and the watched link. The Host API and durable storage path run against a real disposable test Host; schema and transition tests use fixed GitHub-shaped JSON and do not contact GitHub. The browser journey tooling/dshx/e2e/features/pull-requests.feature (pnpm check:e2e pull-requests) seeds a jj repository with a bare remote and a stub gh on the Host PATH, runs the palette command, confirms the dialog and checks the pushed branch and the created, polled pull request.

