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 22, 12:00 UTC
fix(mobile): show draft review comments inline and in the count (#23602)
Co-authored-by: GPT-6.1 Sol <noreply@openai.com> Co-authored-by: maria-rcks <maria@kuuro.net>
Victor Vogel committed
Oct 30, 2026 at 15:54 UTC
72986b483ad5913cdbc1147017cd5fb7d541a9b4
5 files changed
+117
-11
apps/mobile/src/features/review/ReviewSheet.tsx
+2
-1
@@ -435,7 +435,7 @@ export function ReviewSheet(props: ReviewSheetProps) {
435
const environment = useEnvironmentPresentation(environmentId);
436
const retryEnvironment = useAtomCommand(environmentCatalog.retryNow, "environment retry");
437
const isEnvironmentReady = environment.presentation?.connection.phase === "connected";
438
- const { draftMessage } = useThreadDraftForThread({ environmentId, threadId });
438
+ const { draftMessage, draftContext } = useThreadDraftForThread({ environmentId, threadId });
439
const reviewCache = useReviewCacheForThread({ environmentId, threadId });
440
const { selectedThreadCwd } = useSelectedThreadWorktree();
441
const columnMetrics = useNativeColumnLayoutMetrics();
@@ -475,6 +475,7 @@ export function ReviewSheet(props: ReviewSheetProps) {
475
cwd: selectedThreadCwd,
476
selectedSection,
477
draftMessage,
478
+ draftContext,
479
});
480
// Expo may return null before registration or in older binaries; use the fallback.
481
const NativeReviewDiffView = resolveNativeReviewDiffView();
apps/mobile/src/features/review/reviewCommentSelection.test.ts
+72
@@ -1,4 +1,8 @@
1
import { describe, expect, it } from "vite-plus/test";
2
+import { upgradeLegacyContextMessage } from "@t3tools/shared/composerContextLegacy";
3
+import { formatComposerContextReference } from "@t3tools/shared/composerContextReferences";
4
+
5
+import { pullRequestComposerContext } from "../../lib/composerContext";
6
7
import {
8
clearReviewCommentTarget,
@@ -50,6 +54,74 @@ function makeTarget(): ReviewCommentTarget {
54
}
55
56
describe("review comment serialization", () => {
57
+ it("excludes a linked pull request chip from draft review comments", () => {
58
+ const record = pullRequestComposerContext(
59
+ {
60
+ number: 42,
61
+ title: "Fix checkout",
62
+ url: "https://github.com/example/repo/pull/42",
63
+ headBranch: "fix-checkout",
64
+ baseBranch: "main",
65
+ state: "open",
66
+ isDraft: false,
67
+ },
68
+ "pr-42",
69
+ );
70
+
71
+ expect(
72
+ parseReviewInlineComments(formatComposerContextReference(record), {
73
+ version: 1,
74
+ records: [record],
75
+ }),
76
+ ).toEqual([]);
77
+ });
78
+
79
+ it("reads an added review comment after the composer upgrades it to a context chip", () => {
80
+ const upgraded = upgradeLegacyContextMessage(
81
+ formatReviewCommentContext(makeTarget(), "Please keep this configurable."),
82
+ );
83
+ const comments = parseReviewInlineComments(upgraded.text, {
84
+ version: 1,
85
+ records: upgraded.records,
86
+ });
87
+
88
+ expect(comments).toEqual([
89
+ {
90
+ id: upgraded.records[0]!.contextId,
91
+ sectionId: "section-1",
92
+ sectionTitle: "Working tree",
93
+ filePath: "apps/demo/src/main.ts",
94
+ startIndex: 0,
95
+ endIndex: 1,
96
+ rangeLabel: "7",
97
+ text: "Please keep this configurable.",
98
+ diff: "@@ -7,1 +7,1 @@\n-const retryLimit = 2;\n+const retryLimit = 4;",
99
+ fenceLanguage: "diff",
100
+ },
101
+ ]);
102
+ });
103
+
104
+ it("keeps legacy comments and counts a typed comment only while its chip is present", () => {
105
+ const upgraded = upgradeLegacyContextMessage(
106
+ formatReviewCommentContext(makeTarget(), "Typed comment"),
107
+ );
108
+ const context = { version: 1, records: upgraded.records } as const;
109
+ const legacy = formatReviewCommentContext(makeTarget(), "Legacy comment");
110
+ const comments = parseReviewInlineComments(
111
+ `${legacy}\n${upgraded.text}\n${upgraded.text}`,
112
+ context,
113
+ );
114
+
115
+ expect(comments.map((comment) => comment.text)).toEqual(["Legacy comment", "Typed comment"]);
116
+ expect(parseReviewInlineComments(legacy, context).map((comment) => comment.text)).toEqual([
117
+ "Legacy comment",
118
+ ]);
119
+ expect(parseReviewInlineComments("", context)).toEqual([]);
120
+ expect(
121
+ parseReviewInlineComments(upgraded.text.replace("/review-comment/", "/mention/"), context),
122
+ ).toEqual([]);
123
+ });
124
+
125
it("keeps closing-tag text inside a chip label within a real review body", () => {
126
const body = "Before [</review_comment>](t3-context://v1/mention/context-1) after";
127
const serialized = `<review_comment sectionId="s" filePath="app.ts" startIndex="0" endIndex="0">${body}</review_comment>`;
apps/mobile/src/features/review/reviewCommentSelection.ts
+36
-6
@@ -1,5 +1,9 @@
1
import { useSyncExternalStore } from "react";
2
-import { replaceComposerContextReferences } from "@t3tools/shared/composerContextReferences";
2
+import type { OrchestrationMessageContext } from "@t3tools/contracts";
3
+import {
4
+ collectComposerContextReferences,
5
+ replaceComposerContextReferences,
6
+} from "@t3tools/shared/composerContextReferences";
7
8
import type { ReviewRenderableLineRow } from "./reviewModel";
9
@@ -357,11 +361,10 @@ export function formatReviewCommentContext(target: ReviewCommentTarget, comment:
361
].join("\n");
362
}
363
360
-export function countReviewCommentContexts(value: string): number {
361
- return Array.from(value.matchAll(/<review_comment\b/g)).length;
362
-}
363
-
364
-export function parseReviewInlineComments(value: string): ReadonlyArray<ReviewInlineComment> {
364
+export function parseReviewInlineComments(
365
+ value: string,
366
+ context?: OrchestrationMessageContext,
367
+): ReadonlyArray<ReviewInlineComment> {
368
const comments: ReviewInlineComment[] = [];
369
// Mask chip delimiters: labels containing </review_comment> would otherwise truncate the block.
370
const masked = replaceComposerContextReferences(value, (reference) =>
@@ -385,6 +388,33 @@ export function parseReviewInlineComments(value: string): ReadonlyArray<ReviewIn
388
389
comments.push(comment);
390
}
391
+ const referencedIds = new Set(
392
+ collectComposerContextReferences(value)
393
+ .filter((reference) => reference.kind === "review-comment")
394
+ .map((reference) => reference.contextId),
395
+ );
396
+ for (const record of context?.records ?? []) {
397
+ if (
398
+ record.kind !== "review-comment" ||
399
+ "payload" in record ||
400
+ record.sectionId.startsWith("pull-request:") ||
401
+ !referencedIds.has(record.contextId)
402
+ ) {
403
+ continue;
404
+ }
405
+ comments.push({
406
+ id: record.contextId,
407
+ sectionId: record.sectionId,
408
+ sectionTitle: record.sectionTitle,
409
+ filePath: record.filePath,
410
+ startIndex: record.startIndex,
411
+ endIndex: record.endIndex,
412
+ rangeLabel: record.rangeLabel,
413
+ text: record.text,
414
+ diff: record.diff,
415
+ ...(record.fenceLanguage !== undefined ? { fenceLanguage: record.fenceLanguage } : {}),
416
+ });
417
+ }
418
return comments;
419
}
420
apps/mobile/src/features/review/useReviewDiffData.ts
+6
-4
@@ -1,7 +1,7 @@
1
import { useCallback, useContext, useEffect, useMemo, useState } from "react";
2
import { formatDiffCount } from "@t3tools/client-runtime/diff-count";
3
4
-import { countReviewCommentContexts, parseReviewInlineComments } from "./reviewCommentSelection";
4
+import { parseReviewInlineComments } from "./reviewCommentSelection";
5
import { getCachedNativeReviewDiffData } from "./nativeReviewDiffAdapter";
6
import { getCachedReviewParsedDiff } from "./reviewState";
7
import {
@@ -14,6 +14,7 @@ import {
14
15
import type {
16
EnvironmentId,
17
+ OrchestrationMessageContext,
18
ReviewDiffFileStat,
19
ReviewDiffPreviewSource,
20
} from "@t3tools/contracts";
@@ -126,8 +127,9 @@ export function useReviewDiffData(input: {
127
readonly cwd: string | null;
128
readonly selectedSection: ReviewSectionItem | null;
129
readonly draftMessage: string;
130
+ readonly draftContext: OrchestrationMessageContext | undefined;
131
}) {
130
- const { draftMessage, selectedSection, threadKey } = input;
132
+ const { draftMessage, draftContext, selectedSection, threadKey } = input;
133
const selectedSectionId = selectedSection?.id ?? null;
134
const source = selectedSection?.source;
135
const lazySource = source?.truncated && source.files ? source : null;
@@ -230,7 +232,7 @@ export function useReviewDiffData(input: {
232
() => formatHeaderDiffSummary(parsedDiff, selectedSection?.files),
233
[parsedDiff, selectedSection?.files],
234
);
233
- const inlineReviewComments = parseReviewInlineComments(draftMessage);
235
+ const inlineReviewComments = parseReviewInlineComments(draftMessage, draftContext);
236
const selectedSectionInlineComments = useMemo(() => {
237
if (!selectedSectionId || inlineReviewComments.length === 0) {
238
return EMPTY_INLINE_REVIEW_COMMENTS;
@@ -241,7 +243,7 @@ export function useReviewDiffData(input: {
243
parsedDiff,
244
comments: selectedSectionInlineComments,
245
});
244
- const pendingReviewCommentCount = countReviewCommentContexts(draftMessage);
246
+ const pendingReviewCommentCount = inlineReviewComments.length;
247
248
// oxlint-disable-next-line t3code/no-unreasoned-state-sync -- records review perf marks and diagnostic logs once a parsed diff has committed
249
useEffect(() => {
apps/mobile/src/state/use-thread-composer-state.ts
+1
@@ -164,6 +164,7 @@ export function useThreadDraftForThread(input: {
164
165
return {
166
draftMessage: draft.text,
167
+ draftContext: draft.context,
168
draftAttachments: draft.attachments,
169
};
170
}