Skip to content

Commit 90642a1

Browse files
Merge main into feat/pr-composer-references
Keeps this branch's completion names over #30747's squashed mention names, and drops the mobile mention hook and suggestions that this branch renamed. Co-Authored-By: Claude Opus 5.5 <[email protected]>
2 parents ac34fe0 + 42a0e91 commit 90642a1

11 files changed

Lines changed: 746 additions & 199 deletions

‎apps/web/src/components/chat/ThreadDetailsPrRow.tsx‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,8 @@ export function ThreadDetailsPrRow({
211211
url: detail.url,
212212
headBranch: detail.headBranch,
213213
baseBranch: detail.baseBranch,
214+
state: detail.state,
215+
isDraft: detail.isDraft,
214216
reviewThreads: [],
215217
comments: [],
216218
checks: detail.checks,

‎apps/web/src/components/pullRequest/PullRequestCodeTab.tsx‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,11 @@ import { useLocalStorage } from "~/hooks/useLocalStorage";
4747
import { useClientSettings, updateClientSettings } from "~/hooks/useSettings";
4848
import { useRenderedAppearance } from "~/hooks/useTheme";
4949
import { areAllDiffFilesCollapsed } from "~/lib/diffCollapse";
50-
import { pullRequestFindingKey, type PullRequestFinding } from "./pullRequestDetail.logic";
50+
import {
51+
pullRequestFindingKey,
52+
type PullRequestChatSubject,
53+
type PullRequestFinding,
54+
} from "./pullRequestDetail.logic";
5155
import {
5256
canEditPullRequestComment,
5357
canResolvePullRequestThread,
@@ -338,6 +342,7 @@ function PullRequestCodeTab({
338342
pendingFinding,
339343
fixFindingLabel = "Fix in a thread",
340344
onFixFinding,
345+
onAddToChat,
341346
onAddToAgentSelection,
342347
onRefresh,
343348
refreshToken = 0,
@@ -353,6 +358,8 @@ function PullRequestCodeTab({
353358
pendingFinding?: string | null;
354359
fixFindingLabel?: string;
355360
onFixFinding?: (finding: PullRequestFinding) => void;
361+
/** Absent where there is no composer beside the panel to add a conversation to. */
362+
onAddToChat?: (subject: PullRequestChatSubject) => void;
356363
onAddToAgentSelection?: (input: PullRequestAgentSelectionInput) => void;
357364
onRefresh: () => void;
358365
refreshToken?: number;
@@ -967,6 +974,9 @@ function PullRequestCodeTab({
967974
fixPending={pendingFinding === pullRequestFindingKey({ kind: "thread", thread })}
968975
fixLabel={fixFindingLabel}
969976
{...(onFixFinding ? { onFix: () => onFixFinding({ kind: "thread", thread }) } : {})}
977+
{...(onAddToChat
978+
? { onAddToChat: (loaded) => onAddToChat({ kind: "thread", thread: loaded }) }
979+
: {})}
970980
onLoadMore={async (cursor): Promise<PullRequestThreadCommentsResult | null> => {
971981
const result = await loadThreadComments({
972982
environmentId,

‎apps/web/src/components/pullRequest/PullRequestDetailPanel.tsx‎

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,7 @@ import { projectChangeRequestUrl } from "@t3tools/client-runtime/change-request-
22
import { normalizeThreadPullRequestKey } from "@t3tools/client-runtime/thread-pull-requests";
33
import { useAtomValue } from "@effect/atom-react";
44
import { usePullRequestStack } from "~/state/usePullRequestStack";
5-
import {
6-
scopedThreadKey,
7-
scopeProjectRef,
8-
scopeThreadRef,
9-
} from "@t3tools/client-runtime/environment";
5+
import { scopeProjectRef, scopeThreadRef } from "@t3tools/client-runtime/environment";
106
import {
117
isAtomCommandInterrupted,
128
squashAtomCommandFailure,
@@ -53,7 +49,10 @@ import { useCopyToClipboard } from "~/hooks/useCopyToClipboard";
5349
import { isCommandPaletteOpen } from "~/commandPaletteBus";
5450
import { resolveShortcutCommand, type ShortcutMatchContext } from "~/keybindings";
5551
import { primaryServerKeybindingsAtom } from "~/state/server";
56-
import { usePullRequestDefaultMergeMethodResolver } from "./usePullRequestActions";
52+
import {
53+
usePullRequestDefaultMergeMethodResolver,
54+
writeHandoffToComposer,
55+
} from "./usePullRequestActions";
5756
import { offHeadPullRequestCheckoutToast } from "./pullRequestCheckoutToast";
5857
import { usePreparePullRequestThreadAction } from "~/state/sourceControlActions";
5958
import { cn } from "~/lib/utils";
@@ -118,9 +117,9 @@ import {
118117
buildExplainPullRequestHandoff,
119118
buildFixFindingHandoff,
120119
buildFixFindingsHandoff,
120+
buildPullRequestCommentContext,
121+
buildPullRequestContext,
121122
buildResolveConflictsPrompt,
122-
handoffPrompt,
123-
handoffReviewComments,
124123
latestPullRequestReviewOutcomes,
125124
loadingPullRequestCheckoutCommand,
126125
isPullRequestNotFound,
@@ -140,9 +139,9 @@ import {
140139
isPullRequestConflicting,
141140
resolveBaseFreshness,
142141
resolvePullRequestMergeMethod,
142+
type PullRequestChatSubject,
143143
type PullRequestFinding,
144144
shouldRefreshPullRequestActivity,
145-
stripPullRequestHandoffReferences,
146145
} from "./pullRequestDetail.logic";
147146
import { resolvePickableEnvironments } from "./pullRequestProjectAssignment.logic";
148147
import { PullRequestChecksPopover } from "./PullRequestChecksPopover";
@@ -209,12 +208,6 @@ const TABS: ReadonlyArray<{ value: PullRequestDetailTab; label: string }> = [
209208
const loadCodeTab = () => import("./PullRequestCodeTab");
210209
const PullRequestCodeTab = lazy(loadCodeTab);
211210

212-
// Persist handoffs across unmounts; replace only unchanged contributions to preserve user edits.
213-
const lastHandoffPromptByDraft = new Map<string, string>();
214-
215-
const composerTargetKey = (target: ScopedThreadRef | DraftId): string =>
216-
typeof target === "string" ? target : scopedThreadKey(target);
217-
218211
function reportCheckoutCommandError(error: Error) {
219212
toastManager.add({
220213
type: "error",
@@ -758,43 +751,6 @@ export function PullRequestDetailPanel({
758751
if (guideWriter.data?.guide == null) selectTab("guide");
759752
};
760753

761-
const writeTaskToComposer = (target: ScopedThreadRef | DraftId, task: ThreadTask) => {
762-
const store = useComposerDraftStore.getState();
763-
const draft = store.getComposerDraft(target);
764-
const key = composerTargetKey(target);
765-
const previousCommentIds = new Set((draft?.reviewComments ?? []).map((comment) => comment.id));
766-
const repeatedCommentIds = new Set(
767-
(task.reviewComments ?? [])
768-
.filter((comment) => previousCommentIds.has(comment.id))
769-
.map((comment) => comment.id),
770-
);
771-
const promptWithoutPreviousHandoff = stripPullRequestHandoffReferences(
772-
draft?.prompt ?? "",
773-
draft?.reviewComments ?? [],
774-
repeatedCommentIds,
775-
);
776-
const prompt = handoffPrompt(
777-
{
778-
prompt: promptWithoutPreviousHandoff,
779-
lastHandoffPrompt: lastHandoffPromptByDraft.get(key),
780-
},
781-
task.prompt,
782-
);
783-
lastHandoffPromptByDraft.set(key, task.prompt);
784-
store.setPrompt(target, prompt);
785-
store.setReviewComments(
786-
target,
787-
handoffReviewComments(draft?.reviewComments ?? [], task.reviewComments ?? []),
788-
);
789-
for (const comment of task.reviewComments ?? []) {
790-
if (!repeatedCommentIds.has(comment.id)) continue;
791-
store.addReviewComment(target, comment, {
792-
allowDuplicateReference: true,
793-
insertAtCaret: false,
794-
});
795-
}
796-
};
797-
798754
const openThreadWithTask = async (
799755
projectRef: ReturnType<typeof scopeProjectRef>,
800756
task: ThreadTask | null,
@@ -808,7 +764,7 @@ export function PullRequestDetailPanel({
808764
));
809765
if (session === null) return null;
810766
if (task === null) return session;
811-
writeTaskToComposer(session.draftId, task);
767+
writeHandoffToComposer(session.draftId, task);
812768
return session;
813769
};
814770

@@ -819,7 +775,7 @@ export function PullRequestDetailPanel({
819775
) => {
820776
if (!detail || handoff !== null) return;
821777
if (attachTarget !== null) {
822-
writeTaskToComposer(attachTarget, task);
778+
writeHandoffToComposer(attachTarget, task);
823779
toastManager.add({
824780
type: "success",
825781
title: "Added to the composer",
@@ -875,7 +831,7 @@ export function PullRequestDetailPanel({
875831
) => {
876832
if (!handoffSummary || handoff !== null) return;
877833
if (attachTarget !== null && task !== null) {
878-
writeTaskToComposer(attachTarget, task);
834+
writeHandoffToComposer(attachTarget, task);
879835
toastManager.add({
880836
type: "success",
881837
title: "Added to the composer",
@@ -1060,6 +1016,43 @@ export function PullRequestDetailPanel({
10601016
);
10611017
};
10621018

1019+
/**
1020+
* Brings a remark into the composer beside this panel, with the pull request it belongs to,
1021+
* and nothing else: what to ask about it is the reader's to write. A remark on a line travels
1022+
* as its whole conversation, the way fixing one does.
1023+
*/
1024+
const addCommentToChat = (subject: PullRequestChatSubject) => {
1025+
if (!detail || attachTarget === null) return;
1026+
const thread =
1027+
subject.kind === "comment"
1028+
? detail.reviewThreads.find((candidate) =>
1029+
candidate.comments.some((comment) => comment.id === subject.comment.id),
1030+
)
1031+
: undefined;
1032+
const comment = buildPullRequestCommentContext(
1033+
detail,
1034+
thread === undefined ? subject : { kind: "thread", thread },
1035+
);
1036+
if (comment === null) return;
1037+
const store = useComposerDraftStore.getState();
1038+
const reference = buildPullRequestContext({
1039+
number: detail.number,
1040+
title: detail.title,
1041+
url: detail.url,
1042+
headBranch: detail.headBranch,
1043+
baseBranch: detail.baseBranch,
1044+
state: detail.state,
1045+
isDraft: detail.isDraft,
1046+
});
1047+
const hasReference = (store.getComposerDraft(attachTarget)?.reviewComments ?? []).some(
1048+
(existing) => existing.pullRequest?.url === detail.url,
1049+
);
1050+
// The active editor may be answering a provider question rather than editing this draft.
1051+
if (!hasReference) store.addReviewComment(attachTarget, reference, { insertAtCaret: false });
1052+
store.addReviewComment(attachTarget, comment, { insertAtCaret: false });
1053+
toastManager.add({ type: "success", title: "Added to the composer" });
1054+
};
1055+
10631056
const startCheckout = (mode: "worktree" | "local") => {
10641057
if (!handoffSummary) return;
10651058
void startHandoff(`checkout:${mode}`, null, mode);
@@ -1075,6 +1068,8 @@ export function PullRequestDetailPanel({
10751068
url: detail.url,
10761069
headBranch: detail.headBranch,
10771070
baseBranch: detail.baseBranch,
1071+
state: detail.state,
1072+
isDraft: detail.isDraft,
10781073
finding,
10791074
}),
10801075
);
@@ -1090,6 +1085,8 @@ export function PullRequestDetailPanel({
10901085
url: detail.url,
10911086
headBranch: detail.headBranch,
10921087
baseBranch: detail.baseBranch,
1088+
state: detail.state,
1089+
isDraft: detail.isDraft,
10931090
reviewThreads: detail.reviewThreads,
10941091
comments: detail.comments,
10951092
checks: checksStale ? [] : detail.checks,
@@ -1760,6 +1757,7 @@ export function PullRequestDetailPanel({
17601757
fixFindingLabel={handoffLabels.fixFinding}
17611758
fixCheckLabel={handoffLabels.fixCheck}
17621759
{...(canFixFindings ? { onFixFinding: startFixFinding } : {})}
1760+
{...(attachTarget === null ? {} : { onAddToChat: addCommentToChat })}
17631761
onRefresh={refreshDetail}
17641762
onRefreshChecks={refreshFromHost}
17651763
/>
@@ -1817,6 +1815,7 @@ export function PullRequestDetailPanel({
18171815
reference={reference}
18181816
order={timelineOrder}
18191817
onOpenCommit={openCommit}
1818+
{...(attachTarget === null ? {} : { onAddToChat: addCommentToChat })}
18201819
onRefresh={refreshDetail}
18211820
/>
18221821
)}
@@ -1840,6 +1839,7 @@ export function PullRequestDetailPanel({
18401839
pendingFinding={handoff}
18411840
fixFindingLabel={handoffLabels.fixFinding}
18421841
{...(canFixFindings ? { onFixFinding: startFixFinding } : {})}
1842+
{...(attachTarget === null ? {} : { onAddToChat: addCommentToChat })}
18431843
onRefresh={refreshDetail}
18441844
refreshToken={refreshToken}
18451845
backgroundRefreshToken={turnRefresh ?? 0}

‎apps/web/src/components/pullRequest/PullRequestReviewAnnotation.tsx‎

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import type {
77
PullRequestThreadCommentsResult,
88
PullRequestThreadComment,
99
} from "@t3tools/contracts";
10-
import { HammerIcon, MessageSquareIcon, Trash2Icon } from "lucide-react";
10+
import { HammerIcon, MessageSquareIcon, MessageSquarePlusIcon, Trash2Icon } from "lucide-react";
1111
import { Circle, CircleCheck } from "lucide";
1212
import { useRef, useState } from "react";
1313
import { settlePromise, squashAtomCommandFailure } from "@t3tools/client-runtime/state/runtime";
@@ -23,6 +23,7 @@ import { isCommentSubmitShortcut } from "../diffs/commentSubmitShortcut";
2323
import {
2424
editPullRequestThreadComment,
2525
mergePullRequestThreadComments,
26+
visibleBody,
2627
} from "./pullRequestDetail.logic";
2728
import { PullRequestActorLabel } from "./pullRequestPresentation";
2829
import { PullRequestMarkdown } from "./PullRequestMarkdown";
@@ -121,6 +122,7 @@ export function ReviewThreadCard({
121122
fixPending,
122123
fixLabel = "Fix in a thread",
123124
onFix,
125+
onAddToChat,
124126
onReply,
125127
onLoadMore,
126128
canEditComment,
@@ -140,6 +142,11 @@ export function ReviewThreadCard({
140142
fixPending?: boolean;
141143
fixLabel?: string;
142144
onFix?: () => void;
145+
/**
146+
* Absent where there is no composer beside the panel to add the conversation to. Handed the
147+
* thread with every comment the reader has loaded, not only the first page.
148+
*/
149+
onAddToChat?: (thread: PullRequestReviewThread) => void;
143150
onReply: (body: string) => Promise<boolean>;
144151
onLoadMore: (cursor: string) => Promise<PullRequestThreadCommentsResult | null>;
145152
canEditComment: (comment: PullRequestThreadComment) => boolean;
@@ -253,11 +260,22 @@ export function ReviewThreadCard({
253260
{fixPending ? "Preparing..." : fixLabel}
254261
</Button>
255262
) : null}
256-
{canResolve ? (
263+
{onAddToChat && comments.some((comment) => visibleBody(comment.body) !== null) ? (
257264
<Button
258265
size="xs"
259266
variant="ghost"
260267
className={onFix ? undefined : "ml-auto"}
268+
onClick={() => onAddToChat({ ...thread, comments })}
269+
>
270+
<MessageSquarePlusIcon className="size-3" />
271+
Add to chat
272+
</Button>
273+
) : null}
274+
{canResolve ? (
275+
<Button
276+
size="xs"
277+
variant="ghost"
278+
className={onFix || onAddToChat ? undefined : "ml-auto"}
261279
disabled={pending}
262280
onClick={onToggleResolved}
263281
>

0 commit comments

Comments
 (0)