The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 23, 08:00 UTC
feat(web): drag a linked pull request into the composer as a context chip (#20102)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
Julius Marminge committed
Oct 15, 2026 at 19:26 UTC
b67ac65b74feae961f5bdb39e65027bebb99f0cf
6 files changed
+117
-8
apps/web/src/components/chat/ChatComposer.tsx
+12
-1
@@ -6095,11 +6095,22 @@ export const ChatComposer = memo(function ChatComposer(props: ChatComposerProps)
6095
return setContextInsertionHandler(composerDraftTarget, insertContextReferencesAtCaretStable);
6096
}, [composerDraftTarget, insertContextReferencesAtCaretStable, setContextInsertionHandler]);
6097
6098
- // File-tree drags land as mentions. Handled in the capture phase so the
6098
+ // File-tree drags land as mentions, pull request rows as their context chip. Handled in the capture phase so the
6099
// editor never sees the drop; the load-bearing rules (native stop, "move"
6100
// effect, no eager focus) live in makeComposerMentionDragHandlers.
6101
const composerMentionDragHandlers = makeComposerMentionDragHandlers({
6102
insertMentionAtEnd: (text) => insertComposerTextAtEnd(text, { ensureLeadingBoundary: true }),
6103
+ insertPullRequestAtEnd: (pullRequest) => {
6104
+ const comment = buildPullRequestReferenceContext(pullRequest);
6105
+ const inserted = insertComposerTextAtEnd(
6106
+ `${formatInlineContextReference(reviewCommentContextReference(comment))} `,
6107
+ { ensureLeadingBoundary: true },
6108
+ );
6109
+ if (inserted) {
6110
+ addComposerDraftReviewComment(composerDraftTarget, comment, { appendReference: false });
6111
+ }
6112
+ return inserted;
6113
+ },
6114
setDragActive: setIsDragOverComposer,
6115
onInsertRejected: () => {
6116
toastManager.add({
apps/web/src/components/chat/composerMentionDrag.test.ts
+44
-3
@@ -2,19 +2,26 @@ import { describe, expect, it } from "@effect/vitest";
2
3
import {
4
COMPOSER_MENTION_DRAG_TYPE,
5
+ COMPOSER_PULL_REQUEST_DRAG_TYPE,
6
+ encodePullRequestDragPayload,
7
type ComposerMentionDropHost,
8
composerMentionFromTreePath,
9
dataTransferHasComposerMention,
10
makeComposerMentionDragHandlers,
11
} from "./composerMentionDrag.ts";
12
11
-const makeDragEvent = (options?: { mention?: string; types?: ReadonlyArray<string> }) => {
13
+const makeDragEvent = (options?: {
14
+ mention?: string;
15
+ types?: ReadonlyArray<string>;
16
+ format?: string;
17
+}) => {
18
const mention = options?.mention ?? "[index.md](docs/index.md)";
19
+ const format = options?.format ?? COMPOSER_MENTION_DRAG_TYPE;
20
const calls: Array<string> = [];
21
const event = {
22
dataTransfer: {
16
- types: options?.types ?? [COMPOSER_MENTION_DRAG_TYPE, "text/plain"],
17
- getData: (format: string) => (format === COMPOSER_MENTION_DRAG_TYPE ? mention : ""),
23
+ types: options?.types ?? [format, "text/plain"],
24
+ getData: (requested: string) => (requested === format ? mention : ""),
25
dropEffect: "none",
26
},
27
nativeEvent: {
@@ -33,6 +40,10 @@ const makeHost = (insertResult = true) => {
40
log.push(`insert:${text}`);
41
return insertResult;
42
},
43
+ insertPullRequestAtEnd: (pullRequest) => {
44
+ log.push(`pr:${pullRequest.number}`);
45
+ return insertResult;
46
+ },
47
setDragActive: (active) => void log.push(`active:${active}`),
48
onInsertRejected: () => void log.push("rejected"),
49
};
@@ -120,4 +131,34 @@ describe("makeComposerMentionDragHandlers", () => {
131
handlers.onDrop(makeDragEvent({ mention: "" }).event);
132
expect(log).toEqual(["active:false"]);
133
});
134
+
135
+ it("drops a pull request row as a pull request, not as text", () => {
136
+ const { host, log } = makeHost();
137
+ const handlers = makeComposerMentionDragHandlers(host);
138
+ const pullRequest = {
139
+ number: 18094,
140
+ title: "fix(server): queued runs land on the timeline where they started",
141
+ url: "https://github.com/pingdotgg/t3code/pull/18094",
142
+ headBranch: "fix/run-timeline-position",
143
+ baseBranch: "main",
144
+ state: "open",
145
+ isDraft: false,
146
+ } as const;
147
+ handlers.onDrop(
148
+ makeDragEvent({
149
+ format: COMPOSER_PULL_REQUEST_DRAG_TYPE,
150
+ mention: encodePullRequestDragPayload(pullRequest),
151
+ }).event,
152
+ );
153
+ expect(log).toEqual(["active:false", "pr:18094"]);
154
+ });
155
+
156
+ it("ignores a pull request payload that does not decode", () => {
157
+ const { host, log } = makeHost();
158
+ const handlers = makeComposerMentionDragHandlers(host);
159
+ handlers.onDrop(
160
+ makeDragEvent({ format: COMPOSER_PULL_REQUEST_DRAG_TYPE, mention: '{"number":0}' }).event,
161
+ );
162
+ expect(log).toEqual(["active:false"]);
163
+ });
164
});
apps/web/src/components/chat/composerMentionDrag.ts
+29
-3
@@ -1,4 +1,6 @@
1
+import { PullRequestContextMetadata } from "@t3tools/contracts";
2
import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
3
+import { Option, Schema } from "effect";
4
5
/**
6
* Drag payload type carrying a serialized composer mention. Set on drags that
@@ -7,6 +9,18 @@ import { serializeComposerFileLink } from "@t3tools/shared/composerTrigger";
9
*/
10
export const COMPOSER_MENTION_DRAG_TYPE = "application/x-t3code-composer-mention";
11
12
+/**
13
+ * Drag payload type carrying a pull request, as JSON `PullRequestContextMetadata`. Set on drags
14
+ * that start on a pull request row; the composer drops it as the same chip the `#` picker adds.
15
+ */
16
+export const COMPOSER_PULL_REQUEST_DRAG_TYPE = "application/x-t3code-pull-request";
17
+
18
+const PullRequestDragPayload = Schema.fromJsonString(PullRequestContextMetadata);
19
+const decodePullRequestPayload = Schema.decodeUnknownOption(PullRequestDragPayload);
20
+
21
+/** The `COMPOSER_PULL_REQUEST_DRAG_TYPE` data for a pull request row's drag. */
22
+export const encodePullRequestDragPayload = Schema.encodeSync(PullRequestDragPayload);
23
+
24
export function composerMentionFromTreePath(treePath: string): string | null {
25
const relativePath = treePath.replace(/\/+$/, "");
26
if (relativePath.length === 0) {
@@ -16,7 +30,9 @@ export function composerMentionFromTreePath(treePath: string): string | null {
30
}
31
32
export function dataTransferHasComposerMention(types: ReadonlyArray<string>): boolean {
19
- return types.includes(COMPOSER_MENTION_DRAG_TYPE);
33
+ return (
34
+ types.includes(COMPOSER_MENTION_DRAG_TYPE) || types.includes(COMPOSER_PULL_REQUEST_DRAG_TYPE)
35
+ );
36
}
37
38
export interface ComposerMentionDragTransfer {
@@ -41,6 +57,7 @@ export interface ComposerMentionDragEvent {
57
*/
58
export interface ComposerMentionDropHost {
59
insertMentionAtEnd(text: string): boolean;
60
+ insertPullRequestAtEnd(pullRequest: PullRequestContextMetadata): boolean;
61
setDragActive(active: boolean): void;
62
onInsertRejected(): void;
63
}
@@ -76,8 +93,8 @@ export function makeComposerMentionDragHandlers(
93
if (!claim(event)) {
94
return;
95
}
79
- // The tree constrains its drags to effectAllowed "move"; naming any
80
- // other effect makes the browser cancel the drop without firing it.
96
+ // The tree constrains its drags to effectAllowed "move" (pull request links allow
97
+ // anything); naming any other effect makes the browser cancel the drop without firing it.
98
event.dataTransfer.dropEffect = "move";
99
host.setDragActive(true);
100
},
@@ -86,6 +103,15 @@ export function makeComposerMentionDragHandlers(
103
return;
104
}
105
host.setDragActive(false);
106
+ if (event.dataTransfer.types.includes(COMPOSER_PULL_REQUEST_DRAG_TYPE)) {
107
+ const pullRequest = decodePullRequestPayload(
108
+ event.dataTransfer.getData(COMPOSER_PULL_REQUEST_DRAG_TYPE),
109
+ );
110
+ if (Option.isSome(pullRequest) && !host.insertPullRequestAtEnd(pullRequest.value)) {
111
+ host.onInsertRejected();
112
+ }
113
+ return;
114
+ }
115
const mention = event.dataTransfer.getData(COMPOSER_MENTION_DRAG_TYPE);
116
if (mention.length === 0) {
117
return;
apps/web/src/components/pullRequest/ThreadPullRequestsPanel.tsx
+23
@@ -18,6 +18,10 @@ import {
18
import { LegendList } from "@legendapp/list/react";
19
import { memo, useCallback, useMemo, useState } from "react";
20
21
+import {
22
+ COMPOSER_PULL_REQUEST_DRAG_TYPE,
23
+ encodePullRequestDragPayload,
24
+} from "~/components/chat/composerMentionDrag";
25
import { writeTextToClipboard } from "~/hooks/useCopyToClipboard";
26
import { findProjectForChangeRequest, useOpenPrLink } from "~/lib/openPullRequestLink";
27
import { cn } from "~/lib/utils";
@@ -159,6 +163,25 @@ function LinkRowImpl({
163
<a
164
href={link.url}
165
onClick={(event) => openPrLink(event, link.url, threadRef)}
166
+ // The link's own URL still rides along for drops outside the app; the composer takes
167
+ // this payload instead and adds the pull request as a context chip.
168
+ onDragStart={
169
+ snapshot === null
170
+ ? undefined
171
+ : (event) =>
172
+ event.dataTransfer.setData(
173
+ COMPOSER_PULL_REQUEST_DRAG_TYPE,
174
+ encodePullRequestDragPayload({
175
+ number: link.number,
176
+ title: snapshot.title,
177
+ url: link.url,
178
+ headBranch: snapshot.headBranch,
179
+ baseBranch: snapshot.baseBranch,
180
+ state: snapshot.state,
181
+ isDraft: snapshot.isDraft,
182
+ }),
183
+ )
184
+ }
185
className="flex min-w-0 flex-1"
186
>
187
<PullRequestRowLines
apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+7
@@ -1165,6 +1165,13 @@ describe("asking about a change rather than working on it", () => {
1165
expect(context.text).not.toContain("Walk through this pull request");
1166
});
1167
1168
+ it("gives the same number in another repository its own chip", () => {
1169
+ const fork = { ...base, url: "https://github.com/someone/t3code/pull/42" };
1170
+ expect(buildPullRequestReferenceContext(fork).id).not.toBe(
1171
+ buildPullRequestReferenceContext(base).id,
1172
+ );
1173
+ });
1174
+
1175
it("leaves the composer empty, and everything the agent needs in the chip", () => {
1176
const handoff = buildAskAboutPullRequestHandoff(base);
1177
expect(handoff.prompt).toBe("");
apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+2
-1
@@ -1109,7 +1109,8 @@ export function buildPullRequestReferenceContext(
1109
input: PullRequestContextMetadata,
1110
): ReviewCommentContext {
1111
const comment = pullRequestContextComment(input, []);
1112
- return { ...comment, id: `pr-reference:${input.number}` };
1112
+ // Keyed by URL: the draft upserts by id, and two repositories can share a number.
1113
+ return { ...comment, id: `pr-reference:${input.url}` };
1114
}
1115
1116
/** What the agent is asked to do with a question, as opposed to a task. */