Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions apps/web/src/components/BranchToolbarBranchSelector.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -276,8 +276,8 @@ export function BranchToolbarBranchSelector({
const branchByName = new Map(refs.map((refName) => [refName.name, refName] as const));
const normalizedBranchQuery = trimmedBranchQuery.toLowerCase();
const prReference = parsePullRequestReference(trimmedBranchQuery);
const isSelectingWorktreeBase =
effectiveEnvMode === "worktree" && !envLocked && !activeWorktreePath;
const needsWorktree = effectiveEnvMode === "worktree" && !activeWorktreePath;
const isSelectingWorktreeBase = needsWorktree && !envLocked;
const isWorktreeChangeBlockedForRef = (refName: VcsRef) =>
activeProjectCwd !== null &&
isWorktreeChangeBlocked({
Expand Down Expand Up @@ -868,6 +868,12 @@ export function BranchToolbarBranchSelector({
{displayMode === "panel" ? (
<ThreadDetailsThreadPrRows
threadRef={threadRef}
handoffDisabled={needsWorktree && envLocked}
checkout={
branchPr && !needsWorktree
? { target: draftId ?? threadRef, pullRequestUrl: branchPr.url }
: undefined
}
project={activeProject}
branchPr={branchPr}
branchSourceControlProvider={branchStatusQuery.data?.sourceControlProvider}
Expand Down
61 changes: 61 additions & 0 deletions apps/web/src/components/chat/ThreadDetailsPrRow.browser.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,67 @@ it("adds the failing checks to a given composer instead of opening a new thread"
);
});

it.each([
{ name: "its checked-out pull request", checkout: "https://github.com/Owner/Repo/pull/1/" },
{ name: "another pull request's checkout", checkout: "https://github.com/owner/repo/pull/2" },
{ name: "a worktree still being prepared", checkout: undefined },
])("hands off Fix in a thread with $name", async ({ checkout }) => {
await using screen = await setup();
state.status = "failure";
state.projects = [repositoryProject];
state.prepareThread.mockResolvedValue({
_tag: "Success",
value: {
branch: "feature",
worktreePath: "/workspace/pr",
isOnPullRequestHead: true,
pullRequest: { url: "https://github.com/owner/repo/pull/1" },
},
});
state.pullRequests = [
{
host: "github.com",
repository: "owner/repo",
number: 1,
url: "https://github.com/owner/repo/pull/1",
source: "manual",
linkedAt: "2026-10-30T00:00:00.000Z",
snapshot: null,
stack: null,
},
];
useComposerDraftStore.getState().setPrompt(threadRef, "Keep my notes");
await act(async () => {
await screen.rerender(
<ThreadDetailsThreadPrRows
threadRef={threadRef}
project={repositoryProject as never}
handoffDisabled={checkout === undefined}
checkout={
checkout === undefined ? undefined : { target: threadRef, pullRequestUrl: checkout }
}
/>,
);
});
const fix = [...screen.container.querySelectorAll("button")].find(
(button) => button.textContent?.trim() === "Fix",
)!;
await clickButton(screen.container, "Fix");
const prompt = useComposerDraftStore.getState().getComposerDraft(threadRef)?.prompt;
if (checkout === undefined) {
expect(fix.disabled).toBe(true);
expect(prompt).toBe("Keep my notes");
expect(state.prepareThread).not.toHaveBeenCalled();
} else if (checkout.endsWith("/1/")) {
expect(prompt).toContain("Keep my notes");
expect(prompt).toContain("https://github.com/owner/repo/pull/1");
expect(state.prepareThread).not.toHaveBeenCalled();
} else {
expect(prompt).toBe("Keep my notes");
await vi.waitFor(() => expect(state.prepareThread).toHaveBeenCalled());
}
});

const repositoryClone = {
...repositoryProject,
id: ProjectId.make("clone"),
Expand Down
13 changes: 10 additions & 3 deletions apps/web/src/components/chat/ThreadDetailsPrRow.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ export function ThreadDetailsPrRow({
onActed,
onStopWatching,
composerTarget,
handoffDisabled = false,
}: {
environmentId: EnvironmentId;
pr: ThreadPr;
Expand All @@ -113,6 +114,8 @@ export function ThreadDetailsPrRow({
onStopWatching?: (() => void) | undefined;
/** Fix and Resolve write here instead of checking the pull request out in a new thread. */
composerTarget?: ComposerThreadTarget | undefined;
/** Fix and Resolve wait while the thread's own worktree is still being prepared. */
handoffDisabled?: boolean | undefined;
}) {
const serverConfigs = useServerConfigs();
const supportsPullRequests = serverConfigs.get(environmentId) !== undefined;
Expand Down Expand Up @@ -211,7 +214,7 @@ export function ThreadDetailsPrRow({
};

const startResolveConflicts = () => {
if (detail === null) return;
if (detail === null || handoffDisabled) return;
handOff("conflicts", {
prompt: buildResolveConflictsPrompt({
number: detail.number,
Expand All @@ -224,7 +227,7 @@ export function ThreadDetailsPrRow({
};

const startFixChecks = () => {
if (detail === null) return;
if (detail === null || handoffDisabled) return;
handOff(
"findings",
buildFixFindingsHandoff({
Expand Down Expand Up @@ -497,7 +500,11 @@ export function ThreadDetailsPrRow({
size="sm"
part="meta"
tone={trailingAction.destructive ? "destructive" : "primary"}
disabled={actionPending || handoff !== null}
disabled={
actionPending ||
handoff !== null ||
(handoffDisabled && (rowAction === "fix" || rowAction === "resolve"))
}
onClick={trailingAction.onClick}
/>
}
Expand Down
24 changes: 22 additions & 2 deletions apps/web/src/components/chat/ThreadDetailsPrRows.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,15 @@ function ThreadDetailsPrLinkRow({
onActed,
onStopWatching,
composerTarget,
handoffDisabled,
}: {
environmentId: EnvironmentId;
link: ThreadPullRequestLink;
onOpen: (event: ReactMouseEvent<HTMLElement>) => void;
onActed?: (() => void) | undefined;
onStopWatching?: (() => void) | undefined;
composerTarget?: ComposerThreadTarget | undefined;
handoffDisabled?: boolean | undefined;
}) {
const projects = useProjects();
const parsed = sourceControlClients.parseChangeRequestUrl(link.url)?.link;
Expand All @@ -75,6 +77,7 @@ function ThreadDetailsPrLinkRow({
onOpen={onOpen}
onStopWatching={onStopWatching}
composerTarget={composerTarget}
handoffDisabled={handoffDisabled}
{...(onActed ? { onActed } : {})}
/>
);
Expand All @@ -85,12 +88,14 @@ function ThreadDetailsPrRows({
links,
currentLink,
onOpenLink,
composerTargetFor,
...row
}: ComponentProps<typeof ThreadDetailsPrRow> & {
threadRef: ScopedThreadRef;
links: ReadonlyArray<ThreadPullRequestLink>;
currentLink: ThreadPullRequestLink | null;
onOpenLink: (event: ReactMouseEvent<HTMLElement>, url: string) => void;
composerTargetFor: (url: string) => ComposerThreadTarget | undefined;
}) {
const [expanded, setExpanded] = useState(false);
const watch = useAtomCommand(threadEnvironment.watchPullRequest, { reportFailure: true });
Expand Down Expand Up @@ -130,7 +135,8 @@ function ThreadDetailsPrRows({
onOpen={(event) => onOpenLink(event, link.url)}
onActed={row.onActed}
onStopWatching={stopWatching(link)}
composerTarget={row.composerTarget}
composerTarget={composerTargetFor(link.url)}
handoffDisabled={row.handoffDisabled}
/>
))}
</div>
Expand Down Expand Up @@ -163,13 +169,19 @@ export function ThreadDetailsThreadPrRows({
branchSourceControlProvider,
onActed,
composerTarget,
checkout,
handoffDisabled,
}: {
threadRef: ScopedThreadRef;
project: EnvironmentProject | null;
branchPr?: VcsStatusResult["pr"];
branchSourceControlProvider?: VcsStatusResult["sourceControlProvider"];
onActed?: () => void;
/** Every row's Fix and Resolve write here, for threads without a checkout of their own. */
composerTarget?: ComposerThreadTarget | undefined;
/** Only the row for the pull request this thread has checked out writes to its composer. */
checkout?: { target: ComposerThreadTarget; pullRequestUrl: string } | undefined;
handoffDisabled?: boolean | undefined;
}) {
const thread = useQuietThreadShell(threadRef);
const displayed = useThreadDisplayedPullRequest(
Expand All @@ -193,6 +205,12 @@ export function ThreadDetailsThreadPrRows({
projects.filter((candidate) => candidate.environmentId === threadRef.environmentId),
parsed,
) ?? project);
const composerTargetFor = (prUrl: string) =>
composerTarget ??
(checkout !== undefined &&
sourceControlClients.isSameChangeRequest(prUrl, checkout.pullRequestUrl)
? checkout.target
: undefined);
if (number === undefined || url === undefined) return null;
return (
<ThreadDetailsPrRows
Expand All @@ -209,7 +227,9 @@ export function ThreadDetailsThreadPrRows({
label={`#${number}${pr?.title.trim() ? `: ${pr.title}` : ""}`}
openAriaLabel={url}
onOpen={(event) => openPrLink(event, url)}
composerTarget={composerTarget}
composerTarget={composerTargetFor(url)}
composerTargetFor={composerTargetFor}
handoffDisabled={handoffDisabled}
{...(onActed ? { onActed } : {})}
/>
);
Expand Down
Loading