Skip to content

Commit 0f2649c

Browse files
refactor(source-control): pull request behaviour comes from forge capabilities
The pull request service, orchestration, contracts and agent prompts still decided forge behaviour by name: the watch waited for missing checks only when the provider was "github", the sync reactor matched only `gh pr` and `glab mr` merge commands, routing identity was typed and checked as the "github" literal, contracts carried every forge's install and sign-in text, the generic listing held GitHub's search-index workaround, and the Code tab collapsed every review comment range to one line because only GitHub could carry one, so no host got ranged comments. Forges now declare these. Pull request capabilities gain checksAlwaysReport (GitHub) and review.rangeComment (GitHub); providers gain unavailableRequirement (each forge's own text) and listsAcrossMayOmitRepositories (GitHub); client definitions gain changeRequestCloseCommand (gh pr merge|close and gh stack merge, glab mr, cafe pr|stack, tea pr|pulls and fj pr, az repos pr update --status completed|abandoned; Bitbucket has no CLI). The service puts the requirement on PullRequestUnavailableError.requirement, returns the provider's kind from routingIdentity, and the client routes when the source server answers and the alternate names the same kind. Review comment drafts gain an optional startPosition, which GitHub sends as start_line/start_side; the Code tab and the guide excerpts keep a selection's first line within one hunk when the host supports it. Agent-facing text and the agent-credit setting no longer name GitHub. Compatibility: every new field is optional. A new client reading an old server gets no requirement (generic message, as for GitCafe today), no rangeComment (one-line comments as before) and a "github" routing identity, which is still a kind. An old client reading a new server ignores the new fields; its unavailable messages fall back to its generic text, and a routing identity of another kind (none exists yet) would fail to decode and skip routing. Behaviour changes: GitHub review comments can span lines. A run that merges or closes with cafe, tea, fj or az refreshes its links at once. A host without listsAcrossMayOmitRepositories believes its cross-repository read's silence (only GitHub implements that read today). Co-Authored-By: Claude Opus 5.5 <[email protected]>
1 parent 4963bd2 commit 0f2649c

56 files changed

Lines changed: 480 additions & 244 deletions

File tree

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎apps/mobile/src/features/settings/SettingsServerControlsRouteScreen.tsx‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -368,7 +368,7 @@ function ServerSettingsDetail(props: { readonly page: SettingsPage }) {
368368
<SettingsSwitchRow
369369
icon={PullRequestGlyph.merged}
370370
label="Remove agent credits when merging"
371-
subtitle="Remove recognized agent credits from GitHub merge and squash messages, keeping human co-authors. Includes auto-merge. Excludes merge queues, stack merges, and existing commits."
371+
subtitle="Remove recognized agent credits from merge and squash messages on hosts that support it, keeping human co-authors. Includes auto-merge. Excludes merge queues, stack merges, and existing commits."
372372
value={uniform("removeAgentCreditsOnMerge")}
373373
disabled={disabledFor("removeAgentCreditsOnMerge")}
374374
onValueChange={(value) => write({ removeAgentCreditsOnMerge: value })}

‎apps/server/src/mcp/toolkits/pullRequests/tools.ts‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export const PullRequestTargetInput = Schema.Struct({
4343
url: Schema.optional(
4444
TrimmedNonEmptyString.annotate({
4545
description:
46-
"The pull request's web URL, for example https://github.com/owner/repo/pull/123. Preferred when you have it; host, repository and number are read from it.",
46+
"The pull request's web URL as its host shows it, for example https://git.example.com/owner/repo/pull/123 or https://git.example.com/group/project/-/merge_requests/123. Preferred when you have it; host, repository and number are read from it.",
4747
}),
4848
),
4949
repository: Schema.optional(
@@ -60,7 +60,7 @@ export const PullRequestTargetInput = Schema.Struct({
6060
host: Schema.optional(
6161
TrimmedNonEmptyString.annotate({
6262
description:
63-
"Host the repository lives on, for example github.com. Defaults to the host of this thread's project.",
63+
"Host the repository lives on, for example git.example.com. Defaults to the host of this thread's project.",
6464
}),
6565
),
6666
});

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.test.ts‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1337,7 +1337,11 @@ describe("PullRequestSyncReactor", () => {
13371337
),
13381338
);
13391339

1340-
it.effect("reads open links fresh only when a run that ran a merge command ends", () =>
1340+
it.effect.each([
1341+
"gh pr merge 7 --squash 2>&1 | tail -3",
1342+
"cafe pr merge 7 --squash",
1343+
"az repos pr update --id 7 --status completed",
1344+
])("reads open links fresh only when a run that ran `%s` ends", (mergeCommand) =>
13411345
Effect.scoped(
13421346
Effect.gen(function* () {
13431347
yield* TestClock.setTime(Date.parse(NOW));
@@ -1366,7 +1370,7 @@ describe("PullRequestSyncReactor", () => {
13661370
yield* Queue.offerAll(fixture.domainEvents, [
13671371
commandRan(ThreadId.make("other"), "gh pr view 9"),
13681372
runUpdated(ThreadId.make("other"), "completed"),
1369-
commandRan(ThreadId.make("agent"), "gh pr merge 7 --squash 2>&1 | tail -3"),
1373+
commandRan(ThreadId.make("agent"), mergeCommand),
13701374
runUpdated(ThreadId.make("agent"), "completed"),
13711375
]);
13721376
yield* Queue.take(fixture.snapshotReads);

‎apps/server/src/orchestration-v2/PullRequestSyncReactor.ts‎

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,14 @@ import { isTerminalRunStatus } from "./ThreadManagementService.ts";
3939
const SLOW_SYNC_INTERVAL_MS = 15 * 60 * 1_000;
4040
// Every server polls every open linked pull request, and most of them sit untouched for days.
4141
// One nobody has updated for QUIET_AFTER_MS is read on the quiet cadence instead of each sweep;
42-
// requested refreshes, watches and `gh pr merge` still read it at once.
42+
// requested refreshes, watches and a host CLI's merge command still read it at once.
4343
const QUIET_AFTER_MS = 30 * 60 * 1_000;
4444
const QUIET_SYNC_INTERVAL_MS = 5 * 60 * 1_000;
45-
const PULL_REQUEST_CLOSE_COMMAND = /\b(?:gh\s+pr|glab\s+mr)\s+(?:merge|close)\b/u;
45+
46+
const isChangeRequestCloseCommand = (command: string) =>
47+
sourceControlClients.definitions.some(
48+
(definition) => definition.changeRequestCloseCommand?.test(command) === true,
49+
);
4650

4751
const isPullRequestProviderError = Schema.is(PullRequestProviderError);
4852

@@ -533,14 +537,14 @@ export const make = Effect.gen(function* () {
533537
requestSync,
534538
{ discard: true },
535539
);
536-
// An agent can merge or close its pull request from a shell (`gh pr merge`), which
540+
// An agent can merge or close its pull request from a shell with its host's CLI, which
537541
// sends no merge notification. When a run that ran such a command ends, read the
538542
// thread's open links fresh, so settlement does not wait for the next sweep and the
539543
// cached summary. Other runs add no host reads.
540544
case "turn-item.updated":
541545
if (
542546
event.payload.type === "command_execution" &&
543-
PULL_REQUEST_CLOSE_COMMAND.test(event.payload.input)
547+
isChangeRequestCloseCommand(event.payload.input)
544548
) {
545549
closeCommandThreads.add(event.threadId);
546550
}

‎apps/server/src/orchestration-v2/pullRequestWatch.forgejoComments.test.ts‎

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { SourceControlProviderKind, type ThreadPullRequestWatch } from "@t3tools/contracts";
1+
import type { ThreadPullRequestWatch } from "@t3tools/contracts";
22
import { assert, describe, it } from "@effect/vitest";
33
import * as Schema from "effect/Schema";
44
import {
@@ -30,7 +30,15 @@ describe("Forgejo comment watch boundary", () => {
3030
wakes: 2,
3131
} satisfies ThreadPullRequestWatch;
3232
const finalDetail = {
33-
provider: SourceControlProviderKind.make("forgejo"),
33+
capabilities: {
34+
diff: true,
35+
comment: true,
36+
actions: [],
37+
mergeMethods: [],
38+
search: false,
39+
review: { inlineComment: true, reply: false, resolve: false, verdicts: [] },
40+
reviewers: { request: true, listCandidates: true },
41+
},
3442
headSha: seen.headSha,
3543
checks: [],
3644
mergeability: "mergeable",

‎apps/server/src/orchestration-v2/pullRequestWatch.test.ts‎

Lines changed: 15 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import {
2-
SourceControlProviderKind,
32
type PullRequestCheck,
43
PullRequestComment,
54
ThreadPullRequestWatch,
@@ -40,8 +39,19 @@ const check = (name: string, status: PullRequestCheck["status"]): PullRequestChe
4039

4140
type Detail = Parameters<typeof evaluatePullRequestWatch>[1];
4241

42+
const capabilities = (checksAlwaysReport: boolean): Detail["capabilities"] => ({
43+
diff: true,
44+
comment: true,
45+
actions: [],
46+
mergeMethods: [],
47+
search: false,
48+
review: { inlineComment: false, reply: false, resolve: false, verdicts: [] },
49+
reviewers: { request: false, listCandidates: false },
50+
checksAlwaysReport,
51+
});
52+
4353
const detail = (overrides: Partial<Detail> = {}): Detail => ({
44-
provider: SourceControlProviderKind.make("github"),
54+
capabilities: capabilities(true),
4555
headSha: "aaaaaaaaaa",
4656
checks: [check("lint", "success"), check("test", "pending")],
4757
mergeability: "mergeable",
@@ -364,11 +374,8 @@ describe("evaluatePullRequestWatch", () => {
364374
assert.deepEqual(pushed.flat(), ["no-checks"]);
365375
});
366376

367-
it("never reports missing checks on a host whose checks it cannot read", () => {
368-
const azure = detail({
369-
provider: SourceControlProviderKind.make("azure-devops"),
370-
checks: [],
371-
});
372-
assert.isTrue(anHourLater(watch(), azure).every((kinds) => kinds.length === 0));
377+
it("never reports missing checks on a host where an empty list says nothing", () => {
378+
const silent = detail({ capabilities: capabilities(false), checks: [] });
379+
assert.isTrue(anHourLater(watch(), silent).every((kinds) => kinds.length === 0));
373380
});
374381
});

‎apps/server/src/orchestration-v2/pullRequestWatch.ts‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import * as DateTime from "effect/DateTime";
1212
* this only stops a chatty bot looping an agent that is replying to it.
1313
*/
1414
export const PULL_REQUEST_WATCH_WAKE_LIMIT = 10;
15-
/** How long a GitHub head may go without any check before the agent is told none reported. */
15+
/** How long a head may go without any check before the agent is told none reported. */
1616
const PULL_REQUEST_WATCH_NO_CHECKS_MS = 15 * 60_000;
1717
const LISTED_ITEMS = 10;
1818
const SNIPPET_LENGTH = 200;
@@ -38,7 +38,7 @@ export function evaluatePullRequestWatch(
3838
watch: ThreadPullRequestWatch,
3939
detail: Pick<
4040
PullRequestDetail,
41-
"provider" | "headSha" | "checks" | "mergeability" | "viewer" | "author"
41+
"capabilities" | "headSha" | "checks" | "mergeability" | "viewer" | "author"
4242
>,
4343
remarks: ReadonlyArray<PullRequestComment> | null,
4444
now: number,
@@ -95,10 +95,10 @@ export function evaluatePullRequestWatch(
9595

9696
// Only a head never read with checks waits for them: an empty read after checks were seen is
9797
// the failed read above. A watch saved before this field may have seen pending checks on its
98-
// head, so its clock starts only at the next push. Other hosts can lack a checks API (Azure
99-
// DevOps pipelines), where an empty list says nothing, so only GitHub waits.
98+
// head, so its clock starts only at the next push. Where a host's empty list can mean the
99+
// repository runs no checks at all, nothing waits.
100100
let checksAwaitedSince = watch.checksAwaitedSince;
101-
if (detail.provider === "github") {
101+
if (detail.capabilities.checksAlwaysReport === true) {
102102
const awaitedBefore = headMoved
103103
? DateTime.formatIso(DateTime.makeUnsafe(now))
104104
: (watch.checksAwaitedSince ?? null);
@@ -113,7 +113,7 @@ export function evaluatePullRequestWatch(
113113
const own = (detail.viewer ?? detail.author?.login)?.toLowerCase();
114114
const through = Date.parse(watch.remarksThrough);
115115
const activeAt = (remark: PullRequestComment) => remark.editedAt ?? remark.createdAt;
116-
// GitHub times are per second, so remarks at the boundary time are told apart by ID.
116+
// Hosts can stamp remarks to the second, so remarks at the boundary time are told apart by ID.
117117
const fresh = (remarks ?? []).filter((remark) => {
118118
const at = Date.parse(activeAt(remark));
119119
return (
@@ -133,7 +133,7 @@ export function evaluatePullRequestWatch(
133133
if (detail.mergeability === "conflicting" && !watch.conflicting) {
134134
changes.push({ kind: "conflicting" });
135135
}
136-
// "unknown" is GitHub still computing after a push; only a clean answer clears a conflict.
136+
// "unknown" is a host still computing after a push; only a clean answer clears a conflict.
137137
const conflicting =
138138
detail.mergeability === "unknown" ? watch.conflicting : detail.mergeability === "conflicting";
139139

‎apps/server/src/orchestration-v2/runtimeLayer.test.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -183,6 +183,7 @@ const watchedPullRequestDetail = (input: {
183183
actions: [],
184184
mergeMethods: [],
185185
search: false,
186+
checksAlwaysReport: true,
186187
review: { inlineComment: false, reply: false, resolve: false, verdicts: [] },
187188
reviewers: { request: false, listCandidates: false },
188189
},

0 commit comments

Comments
 (0)