@devries-cameron20 / t3code-1 / commits / 973e62373e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Unify git status PR info into a single `pr` field

- Replace `openPr`/`mergedPr` with `pr` in server and contracts - Add PR `state` (`open`/`closed`/`merged`) to git status schema - Resolve latest branch PR via `gh pr list --state all` sorted by `updatedAt`

Julius Marminge committed Feb 15, 2026 at 19:46 UTC 973e62373e5b442ac9c13e0e65f771132c5e66d4
5 files changed +67 -55
apps/server/src/git.ts
+2 -3
@@ -31,7 +31,7 @@ export interface TerminalCommandInput {
31
32 export type TerminalCommandResult = ProcessRunResult;
33
34 -export interface GitStatusDetails extends Omit<GitStatusResult, "openPr" | "mergedPr"> {
34 +export interface GitStatusDetails extends Omit<GitStatusResult, "pr"> {
35 upstreamRef: string | null;
36 }
37
@@ -226,8 +226,7 @@ export class GitCoreService {
226 hasUpstream: details.hasUpstream,
227 aheadCount: details.aheadCount,
228 behindCount: details.behindCount,
229 - openPr: null,
230 - mergedPr: null,
229 + pr: null,
230 });
231 }
232
apps/server/src/gitManager.ts
+48 -28
@@ -7,6 +7,7 @@ import {
7 gitRunStackedActionInputSchema,
8 gitRunStackedActionResultSchema,
9 gitStatusInputSchema,
10 + type GitStatusPrState,
11 type GitRunStackedActionInput,
12 type GitRunStackedActionResult,
13 type GitStatusInput,
@@ -34,18 +35,20 @@ interface GitManagerDeps {
35 gitCore?: GitCoreService;
36 }
37
37 -interface OpenPrInfo {
38 +interface PullRequestInfo {
39 number: number;
40 title: string;
41 url: string;
42 baseRefName: string;
43 headRefName: string;
44 + state: GitStatusPrState;
45 + updatedAt: string | null;
46 }
47
45 -function parseOpenPrList(raw: unknown): OpenPrInfo[] {
48 +function parsePullRequestList(raw: unknown): PullRequestInfo[] {
49 if (!Array.isArray(raw)) return [];
50
48 - const parsed: OpenPrInfo[] = [];
51 + const parsed: PullRequestInfo[] = [];
52 for (const entry of raw) {
53 if (!entry || typeof entry !== "object") continue;
54 const record = entry as Record<string, unknown>;
@@ -54,6 +57,9 @@ function parseOpenPrList(raw: unknown): OpenPrInfo[] {
57 const url = record.url;
58 const baseRefName = record.baseRefName;
59 const headRefName = record.headRefName;
60 + const state = record.state;
61 + const mergedAt = record.mergedAt;
62 + const updatedAt = record.updatedAt;
63 if (typeof number !== "number" || !Number.isInteger(number) || number <= 0) {
64 continue;
65 }
@@ -61,16 +67,34 @@ function parseOpenPrList(raw: unknown): OpenPrInfo[] {
67 typeof title !== "string" ||
68 typeof url !== "string" ||
69 typeof baseRefName !== "string" ||
64 - typeof headRefName !== "string"
70 + typeof headRefName !== "string" ||
71 + typeof state !== "string"
72 ) {
73 continue;
74 }
75 +
76 + let normalizedState: GitStatusPrState;
77 + if ((typeof mergedAt === "string" && mergedAt.trim().length > 0) || state === "MERGED") {
78 + normalizedState = "merged";
79 + } else if (state === "OPEN") {
80 + normalizedState = "open";
81 + } else if (state === "CLOSED") {
82 + normalizedState = "closed";
83 + } else {
84 + continue;
85 + }
86 +
87 + const normalizedUpdatedAt =
88 + typeof updatedAt === "string" && updatedAt.trim().length > 0 ? updatedAt : null;
89 +
90 parsed.push({
91 number,
92 title,
93 url,
94 baseRefName,
95 headRefName,
96 + state: normalizedState,
97 + updatedAt: normalizedUpdatedAt,
98 });
99 }
100 return parsed;
@@ -160,12 +184,13 @@ function normalizeGitHubAuthError(error: unknown): Error | undefined {
184 return undefined;
185 }
186
163 -function toStatusOpenPr(pr: OpenPrInfo): {
187 +function toStatusPr(pr: PullRequestInfo): {
188 number: number;
189 title: string;
190 url: string;
191 baseBranch: string;
192 headBranch: string;
193 + state: GitStatusPrState;
194 } {
195 return {
196 number: pr.number,
@@ -173,6 +198,7 @@ function toStatusOpenPr(pr: OpenPrInfo): {
198 url: pr.url,
199 baseBranch: pr.baseRefName,
200 headBranch: pr.headRefName,
201 + state: pr.state,
202 };
203 }
204
@@ -191,21 +217,12 @@ export class GitManager {
217 const input = gitStatusInputSchema.parse(raw);
218 const details = await this.gitCore.statusDetails(input.cwd);
219
194 - let openPr: ReturnType<typeof toStatusOpenPr> | null = null;
195 - let mergedPr: ReturnType<typeof toStatusOpenPr> | null = null;
220 + let pr: ReturnType<typeof toStatusPr> | null = null;
221 if (details.branch) {
222 try {
198 - if (details.hasUpstream) {
199 - const existing = await this.findOpenPr(input.cwd, details.branch);
200 - if (existing) {
201 - openPr = toStatusOpenPr(existing);
202 - }
203 - }
204 - if (!openPr) {
205 - const merged = await this.findMergedPr(input.cwd, details.branch);
206 - if (merged) {
207 - mergedPr = toStatusOpenPr(merged);
208 - }
223 + const existing = await this.findLatestPr(input.cwd, details.branch);
224 + if (existing) {
225 + pr = toStatusPr(existing);
226 }
227 } catch {
228 // PR lookup is best-effort for status rendering.
@@ -219,8 +236,7 @@ export class GitManager {
236 hasUpstream: details.hasUpstream,
237 aheadCount: details.aheadCount,
238 behindCount: details.behindCount,
222 - openPr,
223 - mergedPr,
239 + pr,
240 };
241 }
242
@@ -390,7 +406,7 @@ export class GitManager {
406 };
407 }
408
393 - private async findOpenPr(cwd: string, branch: string): Promise<OpenPrInfo | null> {
409 + private async findOpenPr(cwd: string, branch: string): Promise<PullRequestInfo | null> {
410 const stdout = await this.runGhStdout(cwd, [
411 "pr",
412 "list",
@@ -401,7 +417,7 @@ export class GitManager {
417 "--limit",
418 "1",
419 "--json",
404 - "number,title,url,baseRefName,headRefName",
420 + "number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt",
421 ]);
422
423 const raw = trimStdout(stdout);
@@ -414,22 +430,22 @@ export class GitManager {
430 throw new Error("GitHub CLI returned invalid PR list JSON.");
431 }
432
417 - const parsed = parseOpenPrList(parsedJson);
433 + const parsed = parsePullRequestList(parsedJson);
434 return parsed[0] ?? null;
435 }
436
421 - private async findMergedPr(cwd: string, branch: string): Promise<OpenPrInfo | null> {
437 + private async findLatestPr(cwd: string, branch: string): Promise<PullRequestInfo | null> {
438 const stdout = await this.runGhStdout(cwd, [
439 "pr",
440 "list",
441 "--head",
442 branch,
443 "--state",
428 - "merged",
444 + "all",
445 "--limit",
430 - "1",
446 + "20",
447 "--json",
432 - "number,title,url,baseRefName,headRefName",
448 + "number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt",
449 ]);
450
451 const raw = trimStdout(stdout);
@@ -442,7 +458,11 @@ export class GitManager {
458 throw new Error("GitHub CLI returned invalid PR list JSON.");
459 }
460
445 - const parsed = parseOpenPrList(parsedJson);
461 + const parsed = parsePullRequestList(parsedJson).toSorted((a, b) => {
462 + const left = a.updatedAt ? Date.parse(a.updatedAt) : 0;
463 + const right = b.updatedAt ? Date.parse(b.updatedAt) : 0;
464 + return right - left;
465 + });
466 return parsed[0] ?? null;
467 }
468
apps/server/src/wsServer.test.ts
+2 -4
@@ -563,8 +563,7 @@ describe("WebSocket Server", () => {
563 hasUpstream: false,
564 aheadCount: 0,
565 behindCount: 0,
566 - openPr: null,
567 - mergedPr: null,
566 + pr: null,
567 }),
568 runStackedAction: vi.fn(),
569 };
@@ -593,8 +592,7 @@ describe("WebSocket Server", () => {
592 hasUpstream: false,
593 aheadCount: 0,
594 behindCount: 0,
596 - openPr: null,
597 - mergedPr: null,
595 + pr: null,
596 });
597 expect(gitManager.status).toHaveBeenCalledWith({ cwd: "/test" });
598 });
packages/contracts/src/git.test.ts
+1 -2
@@ -36,8 +36,7 @@ describe("git contracts", () => {
36 hasUpstream: false,
37 aheadCount: 0,
38 behindCount: 0,
39 - openPr: null,
40 - mergedPr: null,
39 + pr: null,
40 });
41 expect(parsed.branch).toBe("feature/git-actions");
42 expect(parsed.hasWorkingTreeChanges).toBe(true);
packages/contracts/src/git.ts
+14 -18
@@ -72,6 +72,17 @@ export const gitPullInputSchema = z.object({
72 cwd: z.string().trim().min(1),
73 });
74
75 +export const gitStatusPrStateSchema = z.enum(["open", "closed", "merged"]);
76 +
77 +export const gitStatusPrSchema = z.object({
78 + number: z.number().int().positive(),
79 + title: z.string().min(1),
80 + url: z.string().url(),
81 + baseBranch: z.string().min(1),
82 + headBranch: z.string().min(1),
83 + state: gitStatusPrStateSchema,
84 +});
85 +
86 export const gitStatusResultSchema = z.object({
87 branch: z.string().min(1).nullable(),
88 hasWorkingTreeChanges: z.boolean(),
@@ -89,24 +100,7 @@ export const gitStatusResultSchema = z.object({
100 hasUpstream: z.boolean(),
101 aheadCount: z.number().int().nonnegative(),
102 behindCount: z.number().int().nonnegative(),
92 - openPr: z
93 - .object({
94 - number: z.number().int().positive(),
95 - title: z.string().min(1),
96 - url: z.string().url(),
97 - baseBranch: z.string().min(1),
98 - headBranch: z.string().min(1),
99 - })
100 - .nullable(),
101 - mergedPr: z
102 - .object({
103 - number: z.number().int().positive(),
104 - title: z.string().min(1),
105 - url: z.string().url(),
106 - baseBranch: z.string().min(1),
107 - headBranch: z.string().min(1),
108 - })
109 - .nullable(),
103 + pr: gitStatusPrSchema.nullable(),
104 });
105
106 export const gitStackedActionSchema = z.enum(["commit", "commit_push", "commit_push_pr"]);
@@ -146,6 +140,8 @@ export const gitRunStackedActionResultSchema = z.object({
140
141 export type GitStatusInput = z.input<typeof gitStatusInputSchema>;
142 export type GitPullInput = z.input<typeof gitPullInputSchema>;
143 +export type GitStatusPrState = z.infer<typeof gitStatusPrStateSchema>;
144 +export type GitStatusPr = z.infer<typeof gitStatusPrSchema>;
145 export type GitStatusResult = z.infer<typeof gitStatusResultSchema>;
146 export type GitStackedAction = z.infer<typeof gitStackedActionSchema>;
147 export type GitRunStackedActionInput = z.input<typeof gitRunStackedActionInputSchema>;