Compare commits

...
Author SHA1 Message Date
Cursor Agent 8578146fb9 Fix findLatestPr to prioritize open PRs and remove unused icon imports
- findLatestPr: sort open PRs before merged/closed so the UI correctly
  detects existing open PRs and avoids offering duplicate 'Create PR'
- Sidebar: remove unused MonitorIcon, MoonIcon, SunIcon imports
2026-02-20 00:21:21 +00:00
Julius Marmingeandcodex 37e17e9207 Merge origin/main into codething/4efb5794
Co-authored-by: codex <[email protected]>
2026-02-19 16:12:13 -08:00
Julius Marminge 749a2076d8 Merge pull request #77 from pingdotgg/codething/c71d8ea1
Improve DiffPanel turn chip strip navigation and scrolling UX
2026-02-19 16:09:52 -08:00
Julius Marmingeandcodex fe86836b43 Merge origin/main and resolve PR status/sidebar conflicts
Co-authored-by: codex <[email protected]>
2026-02-16 01:01:13 -08:00
Julius Marminge 973e62373e 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`
2026-02-15 19:46:24 -08:00
Julius Marminge dcdb9ac923 Skip local-branch PR checks and dedupe sidebar git status
- server: only query open PRs when the current branch has an upstream; still fall back to merged PR lookup
- tests: cover status behavior for branches without upstream tracking
- web: fetch git status once per cwd, validate query data with schema parsing, and map merged PR badges by thread branch match
2026-02-15 14:28:03 -08:00
Julius Marminge 46347e2bd2 Show merged PR status when no open PR exists
- extend `GitStatusResult` with nullable `mergedPr` metadata
- in server git status, query merged PR only when no open PR is found
- in sidebar, display a `Merged` status pill for threads on branches with merged PRs
- update server/web/contracts tests for the new status shape
2026-02-15 14:04:48 -08:00
10 changed files with 296 additions and 57 deletions

No files matched your search

+2 -2
View File
@@ -31,7 +31,7 @@ export interface TerminalCommandInput {
export type TerminalCommandResult = ProcessRunResult;
export interface GitStatusDetails extends Omit<GitStatusResult, "openPr"> {
export interface GitStatusDetails extends Omit<GitStatusResult, "pr"> {
upstreamRef: string | null;
}
@@ -230,7 +230,7 @@ export class GitCoreService {
hasUpstream: details.hasUpstream,
aheadCount: details.aheadCount,
behindCount: details.behindCount,
openPr: null,
pr: null,
});
}
+69 -4
View File
@@ -169,7 +169,7 @@ describe("GitManager", () => {
await runGit(repoDir, ["remote", "add", "origin", remoteDir]);
await runGit(repoDir, ["push", "-u", "origin", "feature/status-open-pr"]);
const { runner } = createRunnerWithFakeGh({
const { runner, ghCalls } = createRunnerWithFakeGh({
prListSequence: [
JSON.stringify([
{
@@ -190,16 +190,81 @@ describe("GitManager", () => {
const status = await manager.status({ cwd: repoDir });
expect(status.branch).toBe("feature/status-open-pr");
expect(status.openPr).toEqual({
expect(status.pr).toEqual({
number: 13,
title: "Existing PR",
url: "https://github.com/pingdotgg/codething-mvp/pull/13",
baseBranch: "main",
headBranch: "feature/status-open-pr",
state: "open",
});
expect(ghCalls.some((call) => call.includes("--state all"))).toBe(true);
});
it("status is resilient to gh lookup failures and returns openPr null", async () => {
it("status includes merged PR metadata when there is no open PR", async () => {
const repoDir = makeTempDir("t3code-git-manager-");
await initRepo(repoDir);
await runGit(repoDir, ["checkout", "-b", "feature/status-merged-pr"]);
const remoteDir = await createBareRemote();
await runGit(repoDir, ["remote", "add", "origin", remoteDir]);
await runGit(repoDir, ["push", "-u", "origin", "feature/status-merged-pr"]);
const { runner, ghCalls } = createRunnerWithFakeGh({
prListSequence: [
JSON.stringify([
{
number: 26,
title: "Merged PR",
url: "https://github.com/pingdotgg/codething-mvp/pull/26",
baseRefName: "main",
headRefName: "feature/status-merged-pr",
state: "CLOSED",
mergedAt: "2026-02-14T10:00:00Z",
updatedAt: "2026-02-14T10:00:00Z",
},
]),
],
});
const manager = new GitManager({
runProcess: runner,
textGenerator: createTextGenerator(),
});
const status = await manager.status({ cwd: repoDir });
expect(status.branch).toBe("feature/status-merged-pr");
expect(status.pr).toEqual({
number: 26,
title: "Merged PR",
url: "https://github.com/pingdotgg/codething-mvp/pull/26",
baseBranch: "main",
headBranch: "feature/status-merged-pr",
state: "merged",
});
expect(ghCalls.some((call) => call.includes("--state all"))).toBe(true);
});
it("status checks all PR states for branches without upstream", async () => {
const repoDir = makeTempDir("t3code-git-manager-");
await initRepo(repoDir);
await runGit(repoDir, ["checkout", "-b", "feature/local-only"]);
const { runner, ghCalls } = createRunnerWithFakeGh({
prListSequence: ["[]"],
});
const manager = new GitManager({
runProcess: runner,
textGenerator: createTextGenerator(),
});
const status = await manager.status({ cwd: repoDir });
expect(status.branch).toBe("feature/local-only");
expect(status.pr).toBeNull();
expect(ghCalls.some((call) => call.includes("--state all"))).toBe(true);
});
it("status is resilient to gh lookup failures and returns pr null", async () => {
const repoDir = makeTempDir("t3code-git-manager-");
await initRepo(repoDir);
await runGit(repoDir, ["checkout", "-b", "feature/status-no-gh"]);
@@ -217,7 +282,7 @@ describe("GitManager", () => {
const status = await manager.status({ cwd: repoDir });
expect(status.branch).toBe("feature/status-no-gh");
expect(status.openPr).toBeNull();
expect(status.pr).toBeNull();
});
it("creates a commit when working tree is dirty", async () => {
+72 -12
View File
@@ -7,6 +7,7 @@ import {
gitRunStackedActionInputSchema,
gitRunStackedActionResultSchema,
gitStatusInputSchema,
type GitStatusPrState,
type GitRunStackedActionInput,
type GitRunStackedActionResult,
type GitStatusInput,
@@ -34,18 +35,20 @@ interface GitManagerDeps {
gitCore?: GitCoreService;
}
interface OpenPrInfo {
interface PullRequestInfo {
number: number;
title: string;
url: string;
baseRefName: string;
headRefName: string;
state: GitStatusPrState;
updatedAt: string | null;
}
function parseOpenPrList(raw: unknown): OpenPrInfo[] {
function parsePullRequestList(raw: unknown): PullRequestInfo[] {
if (!Array.isArray(raw)) return [];
const parsed: OpenPrInfo[] = [];
const parsed: PullRequestInfo[] = [];
for (const entry of raw) {
if (!entry || typeof entry !== "object") continue;
const record = entry as Record<string, unknown>;
@@ -54,6 +57,9 @@ function parseOpenPrList(raw: unknown): OpenPrInfo[] {
const url = record.url;
const baseRefName = record.baseRefName;
const headRefName = record.headRefName;
const state = record.state;
const mergedAt = record.mergedAt;
const updatedAt = record.updatedAt;
if (typeof number !== "number" || !Number.isInteger(number) || number <= 0) {
continue;
}
@@ -65,12 +71,29 @@ function parseOpenPrList(raw: unknown): OpenPrInfo[] {
) {
continue;
}
let normalizedState: GitStatusPrState;
if ((typeof mergedAt === "string" && mergedAt.trim().length > 0) || state === "MERGED") {
normalizedState = "merged";
} else if (state === "OPEN" || state === undefined || state === null) {
normalizedState = "open";
} else if (state === "CLOSED") {
normalizedState = "closed";
} else {
continue;
}
const normalizedUpdatedAt =
typeof updatedAt === "string" && updatedAt.trim().length > 0 ? updatedAt : null;
parsed.push({
number,
title,
url,
baseRefName,
headRefName,
state: normalizedState,
updatedAt: normalizedUpdatedAt,
});
}
return parsed;
@@ -160,12 +183,13 @@ function normalizeGitHubAuthError(error: unknown): Error | undefined {
return undefined;
}
function toStatusOpenPr(pr: OpenPrInfo): {
function toStatusPr(pr: PullRequestInfo): {
number: number;
title: string;
url: string;
baseBranch: string;
headBranch: string;
state: GitStatusPrState;
} {
return {
number: pr.number,
@@ -173,6 +197,7 @@ function toStatusOpenPr(pr: OpenPrInfo): {
url: pr.url,
baseBranch: pr.baseRefName,
headBranch: pr.headRefName,
state: pr.state,
};
}
@@ -191,12 +216,12 @@ export class GitManager {
const input = gitStatusInputSchema.parse(raw);
const details = await this.gitCore.statusDetails(input.cwd);
let openPr: ReturnType<typeof toStatusOpenPr> | null = null;
if (details.branch && details.hasUpstream) {
let pr: ReturnType<typeof toStatusPr> | null = null;
if (details.branch) {
try {
const existing = await this.findOpenPr(input.cwd, details.branch);
const existing = await this.findLatestPr(input.cwd, details.branch);
if (existing) {
openPr = toStatusOpenPr(existing);
pr = toStatusPr(existing);
}
} catch {
// PR lookup is best-effort for status rendering.
@@ -210,7 +235,7 @@ export class GitManager {
hasUpstream: details.hasUpstream,
aheadCount: details.aheadCount,
behindCount: details.behindCount,
openPr,
pr,
};
}
@@ -380,7 +405,7 @@ export class GitManager {
};
}
private async findOpenPr(cwd: string, branch: string): Promise<OpenPrInfo | null> {
private async findOpenPr(cwd: string, branch: string): Promise<PullRequestInfo | null> {
const stdout = await this.runGhStdout(cwd, [
"pr",
"list",
@@ -391,7 +416,7 @@ export class GitManager {
"--limit",
"1",
"--json",
"number,title,url,baseRefName,headRefName",
"number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt",
]);
const raw = trimStdout(stdout);
@@ -404,7 +429,42 @@ export class GitManager {
throw new Error("GitHub CLI returned invalid PR list JSON.");
}
const parsed = parseOpenPrList(parsedJson);
const parsed = parsePullRequestList(parsedJson);
return parsed[0] ?? null;
}
private async findLatestPr(cwd: string, branch: string): Promise<PullRequestInfo | null> {
const stdout = await this.runGhStdout(cwd, [
"pr",
"list",
"--head",
branch,
"--state",
"all",
"--limit",
"20",
"--json",
"number,title,url,baseRefName,headRefName,state,mergedAt,updatedAt",
]);
const raw = trimStdout(stdout);
if (raw.length === 0) return null;
let parsedJson: unknown;
try {
parsedJson = JSON.parse(raw);
} catch {
throw new Error("GitHub CLI returned invalid PR list JSON.");
}
const parsed = parsePullRequestList(parsedJson).toSorted((a, b) => {
const aOpen = a.state === "open" ? 1 : 0;
const bOpen = b.state === "open" ? 1 : 0;
if (aOpen !== bOpen) return bOpen - aOpen;
const left = a.updatedAt ? Date.parse(a.updatedAt) : 0;
const right = b.updatedAt ? Date.parse(b.updatedAt) : 0;
return right - left;
});
return parsed[0] ?? null;
}
+2 -2
View File
@@ -965,7 +965,7 @@ describe("WebSocket Server", () => {
hasUpstream: false,
aheadCount: 0,
behindCount: 0,
openPr: null,
pr: null,
}),
runStackedAction: vi.fn(),
};
@@ -994,7 +994,7 @@ describe("WebSocket Server", () => {
hasUpstream: false,
aheadCount: 0,
behindCount: 0,
openPr: null,
pr: null,
});
expect(gitManager.status).toHaveBeenCalledWith({ cwd: "/test" });
});
@@ -20,7 +20,7 @@ function status(overrides: Partial<GitStatusResult> = {}): GitStatusResult {
hasUpstream: true,
aheadCount: 0,
behindCount: 0,
openPr: null,
pr: null,
...overrides,
};
}
@@ -29,12 +29,13 @@ describe("when: branch is clean and has an open PR", () => {
it("resolveQuickAction opens the existing PR", () => {
const quick = resolveQuickAction(
status({
openPr: {
pr: {
number: 10,
title: "Open PR",
url: "https://example.com/pr/10",
baseBranch: "main",
headBranch: "feature/test",
state: "open",
},
}),
false,
@@ -45,12 +46,13 @@ describe("when: branch is clean and has an open PR", () => {
it("buildMenuItems disables commit/push and enables open PR", () => {
const items = buildMenuItems(
status({
openPr: {
pr: {
number: 11,
title: "Existing PR",
url: "https://example.com/pr/11",
baseBranch: "main",
headBranch: "feature/test",
state: "open",
},
}),
false,
@@ -147,12 +149,13 @@ describe("when: branch is clean, ahead, and has an open PR", () => {
const quick = resolveQuickAction(
status({
aheadCount: 3,
openPr: {
pr: {
number: 13,
title: "Open PR",
url: "https://example.com/pr/13",
baseBranch: "main",
headBranch: "feature/test",
state: "open",
},
}),
false,
@@ -164,12 +167,13 @@ describe("when: branch is clean, ahead, and has an open PR", () => {
const items = buildMenuItems(
status({
aheadCount: 2,
openPr: {
pr: {
number: 12,
title: "Existing PR",
url: "https://example.com/pr/12",
baseBranch: "main",
headBranch: "feature/test",
state: "open",
},
}),
false,
@@ -204,7 +208,7 @@ describe("when: branch is clean, ahead, and has an open PR", () => {
describe("when: branch is clean, ahead, and has no open PR", () => {
it("resolveQuickAction pushes and creates a PR", () => {
const quick = resolveQuickAction(status({ aheadCount: 2, openPr: null }), false);
const quick = resolveQuickAction(status({ aheadCount: 2, pr: null }), false);
assert.deepInclude(quick, {
kind: "run_action",
action: "commit_push_pr",
@@ -213,7 +217,7 @@ describe("when: branch is clean, ahead, and has no open PR", () => {
});
it("buildMenuItems enables push and create PR, with commit disabled", () => {
const items = buildMenuItems(status({ aheadCount: 2, openPr: null }), false);
const items = buildMenuItems(status({ aheadCount: 2, pr: null }), false);
assert.deepEqual(items, [
{
id: "commit",
@@ -246,14 +250,14 @@ describe("when: branch is clean, ahead, and has no open PR", () => {
describe("when: branch is clean, up to date, and has no open PR", () => {
it("resolveQuickAction returns disabled no-action state", () => {
const quick = resolveQuickAction(
status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, openPr: null }),
status({ aheadCount: 0, behindCount: 0, hasWorkingTreeChanges: false, pr: null }),
false,
);
assert.deepInclude(quick, { kind: "show_hint", label: "Commit", disabled: true });
});
it("buildMenuItems disables commit, push, and create PR", () => {
const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, openPr: null }), false);
const items = buildMenuItems(status({ aheadCount: 0, behindCount: 0, pr: null }), false);
assert.deepEqual(items, [
{
id: "commit",
@@ -290,7 +294,7 @@ describe("when: branch is behind upstream", () => {
});
it("buildMenuItems disables push and create PR", () => {
const items = buildMenuItems(status({ behindCount: 1, openPr: null }), false);
const items = buildMenuItems(status({ behindCount: 1, pr: null }), false);
assert.deepEqual(items, [
{
id: "commit",
@@ -346,12 +350,13 @@ describe("when: working tree has local changes", () => {
const quick = resolveQuickAction(
status({
hasWorkingTreeChanges: true,
openPr: {
pr: {
number: 16,
title: "Existing PR",
url: "https://example.com/pr/16",
baseBranch: "main",
headBranch: "feature/test",
state: "open",
},
}),
false,
@@ -411,7 +416,7 @@ describe("when: on default branch without open PR", () => {
it("resolveQuickAction returns push when branch is ahead", () => {
const quick = resolveQuickAction(
status({ branch: "main", aheadCount: 2, openPr: null }),
status({ branch: "main", aheadCount: 2, pr: null }),
false,
true,
);
@@ -511,7 +516,7 @@ describe("when: HEAD is detached and there are no local changes", () => {
describe("when: branch has no upstream configured", () => {
it("resolveQuickAction returns disabled commit state when clean and no commits are ahead", () => {
const quick = resolveQuickAction(
status({ hasUpstream: false, openPr: null, aheadCount: 0 }),
status({ hasUpstream: false, pr: null, aheadCount: 0 }),
false,
);
assert.deepInclude(quick, {
@@ -526,12 +531,13 @@ describe("when: branch has no upstream configured", () => {
status({
hasUpstream: false,
aheadCount: 0,
openPr: {
pr: {
number: 14,
title: "Existing PR",
url: "https://example.com/pr/14",
baseBranch: "main",
headBranch: "feature/test",
state: "open",
},
}),
false,
@@ -548,12 +554,13 @@ describe("when: branch has no upstream configured", () => {
status({
hasUpstream: false,
aheadCount: 1,
openPr: {
pr: {
number: 15,
title: "Existing PR",
url: "https://example.com/pr/15",
baseBranch: "main",
headBranch: "feature/test",
state: "open",
},
}),
false,
@@ -568,7 +575,7 @@ describe("when: branch has no upstream configured", () => {
it("buildMenuItems disables push and create PR when no commits are ahead", () => {
const items = buildMenuItems(
status({ hasUpstream: false, openPr: null, aheadCount: 0 }),
status({ hasUpstream: false, pr: null, aheadCount: 0 }),
false,
);
assert.deepEqual(items, [
@@ -108,7 +108,7 @@ export function buildMenuItems(
const hasBranch = gitStatus.branch !== null;
const hasChanges = gitStatus.hasWorkingTreeChanges;
const hasOpenPr = gitStatus.openPr !== null;
const hasOpenPr = gitStatus.pr?.state === "open";
const isBehind = gitStatus.behindCount > 0;
const canCommit = !isBusy && hasChanges;
const canPush = !isBusy && hasBranch && !hasChanges && !isBehind && gitStatus.aheadCount > 0;
@@ -178,7 +178,7 @@ export function resolveQuickAction(
const hasBranch = gitStatus.branch !== null;
const hasChanges = gitStatus.hasWorkingTreeChanges;
const hasOpenPr = gitStatus.openPr !== null;
const hasOpenPr = gitStatus.pr?.state === "open";
const isAhead = gitStatus.aheadCount > 0;
const isBehind = gitStatus.behindCount > 0;
const isDiverged = isAhead && isBehind;
@@ -57,7 +57,7 @@ function getMenuActionDisabledReason(
const hasBranch = gitStatus.branch !== null;
const hasChanges = gitStatus.hasWorkingTreeChanges;
const hasOpenPr = gitStatus.openPr !== null;
const hasOpenPr = gitStatus.pr?.state === "open";
const isAhead = gitStatus.aheadCount > 0;
const isBehind = gitStatus.behindCount > 0;
@@ -219,7 +219,7 @@ export default function GitActionsControl({
});
return;
}
const prUrl = gitStatusForActions?.openPr?.url ?? null;
const prUrl = gitStatusForActions?.pr?.state === "open" ? gitStatusForActions.pr.url : null;
if (!prUrl) {
toastManager.add({
type: "error",
@@ -236,7 +236,7 @@ export default function GitActionsControl({
data: threadToastData,
});
});
}, [api, gitStatusForActions?.openPr?.url, threadToastData]);
}, [api, gitStatusForActions?.pr?.state, gitStatusForActions?.pr?.url, threadToastData]);
const runGitActionWithToast = useCallback(
async ({
@@ -296,7 +296,9 @@ export default function GitActionsControl({
stopProgressUpdates();
const resultToast = summarizeGitResult(result);
const prUrl = result.pr.url ?? gitStatusForActions?.openPr?.url;
const existingOpenPrUrl =
gitStatusForActions?.pr?.state === "open" ? gitStatusForActions.pr.url : undefined;
const prUrl = result.pr.url ?? existingOpenPrUrl;
const shouldOfferPushCta = action === "commit" && result.commit.status === "created";
const shouldOfferOpenPrCta =
(action === "commit_push" || action === "commit_push_pr") && !!prUrl && !isDefaultBranch;
@@ -364,7 +366,7 @@ export default function GitActionsControl({
api,
gitStatusForActions?.branch,
gitStatusForActions?.hasWorkingTreeChanges,
gitStatusForActions?.openPr?.url,
gitStatusForActions?.pr,
isDefaultBranch,
maybeConfirmPushToDefaultBranch,
runImmediateGitActionMutation,
+104 -4
View File
@@ -1,7 +1,8 @@
import { TerminalIcon } from "lucide-react";
import { GitPullRequestIcon, TerminalIcon } from "lucide-react";
import { useCallback, useEffect, useMemo, useState } from "react";
import type { ResolvedKeybindingsConfig } from "@t3tools/contracts";
import { useMutation, useQuery, useQueryClient } from "@tanstack/react-query";
import { useMutation, useQueries, useQuery, useQueryClient } from "@tanstack/react-query";
import { gitStatusResultSchema, type GitStatusResult } from "@t3tools/contracts";
import { useNavigate, useParams } from "@tanstack/react-router";
import { useAppSettings } from "../appSettings";
import { isElectron } from "../env";
@@ -12,7 +13,7 @@ import { useStore } from "../store";
import { isChatNewLocalShortcut, isChatNewShortcut } from "../keybindings";
import { type Project, type Thread } from "../types";
import { useNativeApi } from "../hooks/useNativeApi";
import { gitRemoveWorktreeMutationOptions } from "../lib/gitReactQuery";
import { gitRemoveWorktreeMutationOptions, gitStatusQueryOptions } from "../lib/gitReactQuery";
import { serverConfigQueryOptions } from "../lib/serverReactQuery";
import { toastManager } from "./ui/toast";
import { formatWorktreePathForDisplay, getOrphanedWorktreePathForThread } from "../worktreeCleanup";
@@ -50,6 +51,13 @@ interface TerminalStatusIndicator {
pulse: boolean;
}
interface PrStatusIndicator {
label: "PR open" | "PR closed" | "PR merged";
colorClass: string;
}
type ThreadPrState = NonNullable<GitStatusResult["pr"]>["state"] | null;
function hasUnseenCompletion(thread: Thread): boolean {
if (!thread.latestTurnCompletedAt) return false;
const completedAt = Date.parse(thread.latestTurnCompletedAt);
@@ -61,7 +69,10 @@ function hasUnseenCompletion(thread: Thread): boolean {
return completedAt > lastVisitedAt;
}
function threadStatusPill(thread: Thread, hasPendingApprovals: boolean): ThreadStatusPill | null {
function threadStatusPill(
thread: Thread,
hasPendingApprovals: boolean,
): ThreadStatusPill | null {
if (hasPendingApprovals) {
return {
label: "Awaiting response",
@@ -101,6 +112,28 @@ function threadStatusPill(thread: Thread, hasPendingApprovals: boolean): ThreadS
return null;
}
function prStatusIndicator(prState: ThreadPrState): PrStatusIndicator | null {
if (prState === "open") {
return {
label: "PR open",
colorClass: "text-emerald-600 dark:text-emerald-300/90",
};
}
if (prState === "closed") {
return {
label: "PR closed",
colorClass: "text-zinc-500 dark:text-zinc-400/80",
};
}
if (prState === "merged") {
return {
label: "PR merged",
colorClass: "text-violet-600 dark:text-violet-300/90",
};
}
return null;
}
function terminalStatusIndicator(thread: Thread): TerminalStatusIndicator | null {
if (thread.runningTerminalIds.length === 0) {
return null;
@@ -138,6 +171,62 @@ export default function Sidebar() {
}
return map;
}, [state.threads]);
const projectCwdById = useMemo(
() => new Map(state.projects.map((project) => [project.id, project.cwd] as const)),
[state.projects],
);
const threadGitTargets = useMemo(
() =>
state.threads.map((thread) => ({
threadId: thread.id,
branch: thread.branch,
cwd: thread.worktreePath ?? projectCwdById.get(thread.projectId) ?? null,
})),
[projectCwdById, state.threads],
);
const threadGitStatusCwds = useMemo(
() =>
[
...new Set(
threadGitTargets
.filter((target) => target.branch !== null)
.map((target) => target.cwd)
.filter((cwd): cwd is string => cwd !== null),
),
],
[threadGitTargets],
);
const threadGitStatusQueries = useQueries({
queries: threadGitStatusCwds.map((cwd) => {
const base = gitStatusQueryOptions(api, cwd);
return {
...base,
enabled: Boolean(base.enabled),
staleTime: 30_000,
refetchInterval: 60_000,
};
}),
});
const prStateByThreadId = useMemo(() => {
const statusByCwd = new Map<string, GitStatusResult>();
for (let index = 0; index < threadGitStatusCwds.length; index += 1) {
const cwd = threadGitStatusCwds[index];
if (!cwd) continue;
const parsed = gitStatusResultSchema.safeParse(threadGitStatusQueries[index]?.data);
if (parsed.success) {
statusByCwd.set(cwd, parsed.data);
}
}
const map = new Map<string, ThreadPrState>();
for (const target of threadGitTargets) {
const status = target.cwd ? statusByCwd.get(target.cwd) : undefined;
const branchMatches =
target.branch !== null && status?.branch !== null && status?.branch === target.branch;
map.set(target.threadId, branchMatches ? status?.pr?.state ?? null : null);
}
return map;
}, [threadGitStatusCwds, threadGitStatusQueries, threadGitTargets]);
const handleNewThread = useCallback(
(
@@ -524,6 +613,7 @@ export default function Sidebar() {
pendingApprovalByThreadId.get(thread.id) === true,
);
const terminalStatus = terminalStatusIndicator(thread);
const prStatus = prStatusIndicator(prStateByThreadId.get(thread.id) ?? null);
return (
<button
key={thread.id}
@@ -563,6 +653,16 @@ export default function Sidebar() {
<span className="min-w-0 flex-1 truncate text-xs">{thread.title}</span>
</div>
<div className="ml-2 flex shrink-0 items-center gap-1.5">
{prStatus && (
<span
role="img"
aria-label={prStatus.label}
title={prStatus.label}
className={`inline-flex items-center justify-center ${prStatus.colorClass}`}
>
<GitPullRequestIcon className="size-3" />
</span>
)}
{terminalStatus && (
<span
role="img"
+1 -1
View File
@@ -36,7 +36,7 @@ describe("git contracts", () => {
hasUpstream: false,
aheadCount: 0,
behindCount: 0,
openPr: null,
pr: null,
});
expect(parsed.branch).toBe("feature/git-actions");
expect(parsed.hasWorkingTreeChanges).toBe(true);
+14 -9
View File
@@ -73,6 +73,17 @@ export const gitPullInputSchema = z.object({
cwd: z.string().trim().min(1),
});
export const gitStatusPrStateSchema = z.enum(["open", "closed", "merged"]);
export const gitStatusPrSchema = z.object({
number: z.number().int().positive(),
title: z.string().min(1),
url: z.string().url(),
baseBranch: z.string().min(1),
headBranch: z.string().min(1),
state: gitStatusPrStateSchema,
});
export const gitStatusResultSchema = z.object({
branch: z.string().min(1).nullable(),
hasWorkingTreeChanges: z.boolean(),
@@ -90,15 +101,7 @@ export const gitStatusResultSchema = z.object({
hasUpstream: z.boolean(),
aheadCount: z.number().int().nonnegative(),
behindCount: z.number().int().nonnegative(),
openPr: z
.object({
number: z.number().int().positive(),
title: z.string().min(1),
url: z.string().url(),
baseBranch: z.string().min(1),
headBranch: z.string().min(1),
})
.nullable(),
pr: gitStatusPrSchema.nullable(),
});
export const gitStackedActionSchema = z.enum(["commit", "commit_push", "commit_push_pr"]);
@@ -138,6 +141,8 @@ export const gitRunStackedActionResultSchema = z.object({
export type GitStatusInput = z.input<typeof gitStatusInputSchema>;
export type GitPullInput = z.input<typeof gitPullInputSchema>;
export type GitStatusPrState = z.infer<typeof gitStatusPrStateSchema>;
export type GitStatusPr = z.infer<typeof gitStatusPrSchema>;
export type GitStatusResult = z.infer<typeof gitStatusResultSchema>;
export type GitStackedAction = z.infer<typeof gitStackedActionSchema>;
export type GitRunStackedActionInput = z.input<typeof gitRunStackedActionInputSchema>;