@devries-cameron20 / t3code Mirror · read-only / commits / 1da3f3f370
Fork 0

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 21, 08:30 UTC

fix(web): review comments added to the chat arrive whole with their line comments (#38113)

Julius Marminge committed Nov 17, 2026 at 05:12 UTC 1da3f3f3702841a604f76d460b2e5710838a812e
3 files changed +186 -15
apps/web/src/components/pullRequest/pullRequestDetail.logic.test.ts
+97 -2
@@ -1109,7 +1109,11 @@ describe("asking about a change rather than working on it", () => {
1109 });
1110
1111 describe("adding a remark to the chat", () => {
1112 - const pullRequest = { number: 42, url: "https://github.com/pingdotgg/t3code/pull/42" };
1112 + const pullRequest = {
1113 + number: 42,
1114 + url: "https://github.com/pingdotgg/t3code/pull/42",
1115 + reviewThreads: [],
1116 + };
1117 const remark = (id: string, body: string): PullRequestComment => ({
1118 id,
1119 kind: "issue-comment",
@@ -1131,6 +1135,97 @@ describe("adding a remark to the chat", () => {
1135 expect(context?.text).toBe("octocat: Why not reuse the existing parser?");
1136 });
1137
1138 + it("keeps a review summary longer than a fix finding's bound whole", () => {
1139 + const summary = `No critical issues. ${"One misplaced doc comment inline. ".repeat(80)}End.`;
1140 + const context = buildPullRequestCommentContext(pullRequest, {
1141 + kind: "comment",
1142 + comment: remark("c1", summary),
1143 + });
1144 +
1145 + expect(context?.text).toBe(`octocat: ${summary.trim()}`);
1146 + });
1147 +
1148 + it("gives a GitHub review summary its link and the line comments it posted", () => {
1149 + const url = "https://github.com/pingdotgg/t3code/pull/42";
1150 + const review: PullRequestComment = {
1151 + ...remark("r9", "One misplaced doc comment inline."),
1152 + kind: "review",
1153 + url: `${url}#pullrequestreview-9`,
1154 + reviewState: "COMMENTED",
1155 + };
1156 + const lineComment = (id: string, reviewUrl: string, body: string) => ({
1157 + id,
1158 + author: { login: "octocat", name: null, avatarUrl: null },
1159 + body,
1160 + createdAt: "2026-07-03T00:00:00Z",
1161 + url: `${url}#discussion_${id}`,
1162 + reviewUrl,
1163 + });
1164 + const reviewThreads = [
1165 + {
1166 + id: "t1",
1167 + path: "src/main.rs",
1168 + line: 12,
1169 + side: "right" as const,
1170 + isResolved: false,
1171 + isOutdated: false,
1172 + comments: [
1173 + lineComment("r1", `${url}#pullrequestreview-9`, "This doc comment belongs below."),
1174 + lineComment("r2", `${url}#pullrequestreview-10`, "Moved."),
1175 + ],
1176 + },
1177 + ];
1178 +
1179 + expect(
1180 + buildPullRequestCommentContext(
1181 + { ...pullRequest, reviewThreads, reviewThreadsTruncated: false },
1182 + { kind: "comment", comment: review },
1183 + )?.text,
1184 + ).toBe(
1185 + [
1186 + "octocat: One misplaced doc comment inline.",
1187 + `Review: ${url}#pullrequestreview-9`,
1188 + "Line comments in this review:\n\noctocat on `src/main.rs` line 12: This doc comment belongs below.",
1189 + ].join("\n\n"),
1190 + );
1191 + expect(
1192 + buildPullRequestCommentContext(
1193 + { ...pullRequest, reviewThreadsTruncated: false },
1194 + { kind: "comment", comment: review },
1195 + )?.text,
1196 + ).toBe(
1197 + [
1198 + "octocat: One misplaced doc comment inline.",
1199 + `Review: ${url}#pullrequestreview-9`,
1200 + "This review posted no line comments.",
1201 + ].join("\n\n"),
1202 + );
1203 + // A failed or partial thread read must not read as a review with no line comments.
1204 + expect(
1205 + buildPullRequestCommentContext(
1206 + { ...pullRequest, reviewThreadsTruncated: true },
1207 + { kind: "comment", comment: review },
1208 + )?.text,
1209 + ).toBe(
1210 + [
1211 + "octocat: One misplaced doc comment inline.",
1212 + `Review: ${url}#pullrequestreview-9`,
1213 + "No line comments from this review were loaded.",
1214 + "More may exist; see the review link.",
1215 + ].join("\n\n"),
1216 + );
1217 +
1218 + const sent = reviewCommentContextRecord(
1219 + buildPullRequestCommentContext(
1220 + { ...pullRequest, reviewThreads, reviewThreadsTruncated: false },
1221 + { kind: "comment", comment: { ...review, body: `Summary ${"x".repeat(15_990)}` } },
1222 + )!,
1223 + ).text;
1224 + expect(sent).toContain(`Review: ${url}#pullrequestreview-9`);
1225 + expect(sent).toContain("This doc comment belongs below.");
1226 + expect(sent).toContain("more characters of the review summary are omitted");
1227 + });
1228 +
1229 it("keeps every added remark when a later hand-off lands", () => {
1230 const added = ["c1", "c2"].flatMap(
1231 (id) =>
@@ -1223,7 +1318,7 @@ describe("adding a remark to the chat", () => {
1318 });
1319
1320 it("keeps remarks from two repositories apart when their host ids match", () => {
1226 - const other = { number: 42, url: "https://github.com/octocat/fork/pull/42" };
1321 + const other = { ...pullRequest, url: "https://github.com/octocat/fork/pull/42" };
1322 const ids = [pullRequest, other].map(
1323 (target) =>
1324 buildPullRequestCommentContext(target, { kind: "comment", comment: remark("c1", "why?") })
apps/web/src/components/pullRequest/pullRequestDetail.logic.ts
+86 -13
@@ -14,6 +14,7 @@ import {
14 } from "@t3tools/client-runtime/source-control-clients";
15 import * as Schema from "effect/Schema";
16 import {
17 + COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS,
18 GitCommandError,
19 PullRequestDetail,
20 PullRequestOperationError,
@@ -916,6 +917,16 @@ function terminologyForUrl(url: string): ChangeRequestTerminology {
917 .changeRequest;
918 }
919
920 +function reviewThreadText(thread: PullRequestReviewThread): string {
921 + return thread.comments
922 + .flatMap((comment) => {
923 + const body = readableBody(comment.body);
924 + return body === null ? [] : [`${comment.author?.login ?? "ghost"}: ${body}`];
925 + })
926 + .join("\n")
927 + .trim();
928 +}
929 +
930 function reviewThreadContext(
931 thread: PullRequestReviewThread,
932 pullRequestNumber: number,
@@ -931,14 +942,7 @@ function reviewThreadContext(
942 rangeLabel:
943 thread.line === null ? "file" : `L${thread.line}${thread.side === "left" ? " (before)" : ""}`,
944 // Strip bot bookkeeping comments before bounding finding text.
934 - text: bounded(
935 - thread.comments
936 - .flatMap((comment) => {
937 - const body = readableBody(comment.body);
938 - return body === null ? [] : [`${comment.author?.login ?? "ghost"}: ${body}`];
939 - })
940 - .join("\n"),
941 - ),
945 + text: bounded(reviewThreadText(thread)),
946 diff: "",
947 fenceLanguage: inferReviewCommentFenceLanguage(thread.path),
948 };
@@ -1258,15 +1262,25 @@ export type PullRequestChatSubject = Extract<PullRequestFinding, { kind: "thread
1262 * URL because host ids are only unique within a repository. Null when there are no words in it.
1263 */
1264 export function buildPullRequestCommentContext(
1261 - pullRequest: { readonly number: number; readonly url: string },
1265 + pullRequest: {
1266 + readonly number: number;
1267 + readonly url: string;
1268 + readonly reviewThreads: ReadonlyArray<PullRequestReviewThread>;
1269 + readonly reviewThreadsTruncated?: boolean | undefined;
1270 + },
1271 subject: PullRequestChatSubject,
1272 ): ReviewCommentContext | null {
1273 const pullRequestNumber = pullRequest.number;
1274 + // Unlike a batch fix, one remark brought in to talk about travels whole.
1275 if (subject.kind === "thread") {
1266 - const context = reviewThreadContext(subject.thread, pullRequestNumber);
1267 - return context.text === ""
1276 + const text = reviewThreadText(subject.thread);
1277 + return text === ""
1278 ? null
1269 - : { ...context, id: `pr-comment:${pullRequest.url}:thread:${subject.thread.id}` };
1279 + : {
1280 + ...reviewThreadContext(subject.thread, pullRequestNumber),
1281 + id: `pr-comment:${pullRequest.url}:thread:${subject.thread.id}`,
1282 + text,
1283 + };
1284 }
1285 const comment = subject.comment;
1286 const body = readableBody(comment.body);
@@ -1281,7 +1295,7 @@ export function buildPullRequestCommentContext(
1295 startIndex: 0,
1296 endIndex: 0,
1297 rangeLabel: "comment",
1284 - text: bounded(`${author}: ${body}`),
1298 + text: remarkText(`${author}: ${body}`.trim(), reviewLineComments(comment, pullRequest)),
1299 diff: "",
1300 ...(comment.path === null
1301 ? {}
@@ -1289,6 +1303,65 @@ export function buildPullRequestCommentContext(
1303 };
1304 }
1305
1306 +/**
1307 + * The record keeps only the first COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS, so a long summary gives
1308 + * up its tail, never more than half, before the review link and line comments that follow it.
1309 + */
1310 +function remarkText(remark: string, review: ReadonlyArray<string>): string {
1311 + if (review.length === 0) return remark;
1312 + const after = review.join("\n\n");
1313 + const room = Math.max(
1314 + COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS / 2,
1315 + COMPOSER_CONTEXT_REVIEW_TEXT_MAX_CHARS - after.length - 200,
1316 + );
1317 + if (remark.length <= room) return `${remark}\n\n${after}`;
1318 + let end = room;
1319 + const last = remark.charCodeAt(end - 1);
1320 + if (last >= 0xd800 && last <= 0xdbff) end -= 1;
1321 + const omitted = remark.length - end;
1322 + return `${remark.slice(0, end)}\n… ${omitted} more characters of the review summary are omitted; read it at the review link.\n\n${after}`;
1323 +}
1324 +
1325 +/** A GitHub review summary's link and the line comments it posted, which live in other threads. */
1326 +function reviewLineComments(
1327 + comment: PullRequestComment,
1328 + pullRequest: {
1329 + readonly reviewThreads: ReadonlyArray<PullRequestReviewThread>;
1330 + readonly reviewThreadsTruncated?: boolean | undefined;
1331 + },
1332 +): ReadonlyArray<string> {
1333 + const reviewThreads = pullRequest.reviewThreads;
1334 + const anchor = comment.kind === "review" ? parsePullRequestAnchor(comment.url) : null;
1335 + // Only GitHub links line comments to their review, so no other host can say it posted none.
1336 + if (anchor?.kind !== "timeline" || !/^pullrequestreview-\d+$/i.test(anchor.anchor)) return [];
1337 + const posted = reviewThreads.flatMap((thread) =>
1338 + thread.comments.flatMap((lineComment) => {
1339 + const body = readableBody(lineComment.body);
1340 + if (body === null || !pullRequestAnchorMatchesUrl(anchor.anchor, lineComment.reviewUrl)) {
1341 + return [];
1342 + }
1343 + const line = thread.line === null ? "" : ` line ${thread.line}`;
1344 + return [`${lineComment.author?.login ?? "ghost"} on \`${thread.path}\`${line}: ${body}`];
1345 + }),
1346 + );
1347 + // Threads or their replies can be partly loaded; then an empty match proves nothing.
1348 + const complete =
1349 + pullRequest.reviewThreadsTruncated === false &&
1350 + reviewThreads.every((thread) => thread.nextCommentsCursor === undefined);
1351 + const more = complete ? [] : ["More may exist; see the review link."];
1352 + return [
1353 + `Review: ${comment.url}`,
1354 + ...(posted.length === 0
1355 + ? [
1356 + complete
1357 + ? "This review posted no line comments."
1358 + : "No line comments from this review were loaded.",
1359 + ...more,
1360 + ]
1361 + : [`Line comments in this review:\n\n${posted.join("\n\n")}`, ...more]),
1362 + ];
1363 +}
1364 +
1365 const ANSWER_INSTRUCTIONS = [
1366 "Answer the question asked in this message. Do not change any code, and do not check anything out unless asked to.",
1367 ];
apps/web/src/components/pullRequest/usePullRequestDetail.ts
+3
@@ -189,6 +189,9 @@ export function usePullRequestDetail(
189 ),
190 commentsTruncated: activity?.commentsTruncated ?? false,
191 reviewThreads: activity?.reviewThreads ?? [],
192 + ...(activity?.reviewThreadsTruncated === undefined
193 + ? {}
194 + : { reviewThreadsTruncated: activity.reviewThreadsTruncated }),
195 ...(activity?.overviewThreads === undefined
196 ? {}
197 : { overviewThreads: activity.overviewThreads }),