Comment on diff to give agent context #1003
Closedmaskdotdev(GitHub profile, opens in a new tab)wants to merge 5 commits into
main fromrefs/pull/1003/headopened View on GitHubgithub-actions[bot](GitHub profile, opens in a new tab) added labelssize:XXL
github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:unvouched
maskdotdev(GitHub profile, opens in a new tab) changed the title
- apps/web/src/composerDraftStore.test.ts lines 295 to 296OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -158,0 +276,21 @@276+ store.updateDiffContextComment(threadId, "comment-1", {277+ body: "Use the shared helper instead.",278+ });279+280+ expect(281+ useComposerDraftStore.getState().draftsByThreadId[threadId]?.diffContextComments[0]?.body,282+ ).toBe("Use the shared helper instead.");283+ expect(284+ useComposerDraftStore.getState().draftsByThreadId[threadId]?.diffContextComments[0]?.filePath,285+ ).toBe("src/example.ts");286+287+ store.removeDiffContextComment(threadId, "comment-2");288+ expect(289+ useComposerDraftStore290+ .getState()291+ .draftsByThreadId[threadId]?.diffContextComments.map((comment) => comment.id),292+ ).toEqual(["comment-1"]);293+294+ store.clearDiffContextComments(threadId);295+ expect(store.draftsByThreadId[threadId]).toBeUndefined();296+ });apps/web/src/composerDraftStore.ts lines 346 to 346OutdatedResolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -292 +326,21 @@292326327+function normalizeDiffContextCommentDraft(value: unknown): DiffContextCommentDraft | null {328+ if (!value || typeof value !== "object") {329+ return null;330+ }331+ const candidate = value as Record<string, unknown>;332+ const id = candidate.id;333+ const threadId = candidate.threadId;334+ const turnId = candidate.turnId;335+ const filePath = candidate.filePath;336+ const lineStart = candidate.lineStart;337+ const lineEnd = candidate.lineEnd;338+ const side = candidate.side;339+ const body = candidate.body;340+ const createdAt = candidate.createdAt;341+ if (342+ typeof id !== "string" ||343+ id.length === 0 ||344+ typeof threadId !== "string" ||345+ threadId.length === 0 ||346+ !(turnId === null || typeof turnId === "string") ||apps/web/src/components/DiffPanel.logic.ts lines 74 to 84Resolvedby macroscopeapp[bot](GitHub profile, opens in a new tab)@@ -0,0 +64,21 @@64+ if (!filePath) {65+ continue;66+ }67+ fileKeyByPath.set(filePath, fileKey);68+ }69+ }70+71+ return fileKeyByPath;72+}73+74+function toNormalizedLineRange(range: SelectedLineRange): SelectedLineRange {75+ if (range.start <= range.end) {76+ return range;77+ }78+79+ return {80+ start: range.end,81+ end: range.start,82+ ...((range.endSide ?? range.side) ? { side: range.endSide ?? range.side } : {}),83+ ...(range.side ? { endSide: range.side } : {}),84+ };
- apps/web/src/composerDraftStore.ts line 1519Resolvedby maskdotdev(GitHub profile, opens in a new tab)@@ -1387,3 +1511,9 @@13871511 return normalized ? [normalized] : [];13881512 })13891513 : [];1514+ const diffContextComments = Array.isArray(draftCandidate.diffContextComments)1515+ ? draftCandidate.diffContextComments.flatMap((entry) => {1516+ const normalized = normalizeDiffContextCommentDraft(entry);1517+ return normalized ? [normalized] : [];1518+ })1519+ : [];
- @@ -2379,4 +2379,6 @@23792379 if (!sendCtx) return;23802380 const {23812381 images: composerImages,2382+ persistedAttachments: composerPersistedAttachments,23822383 terminalContexts: composerTerminalContexts,2384+ diffContextComments: composerDiffContextComments,@@ -301,5 +307,9 @@301307 row.message.role === "user" &&302308 (() => {303309 const userImages = row.message.attachments ?? [];304- const displayedUserMessage = deriveDisplayedUserMessageState(row.message.text);310+ const extractedDiffComments = extractTrailingDiffContextComments(row.message.text);311+ const displayedUserMessage = deriveDisplayedUserMessageState(312+ extractedDiffComments.promptText,313+ );305314 const terminalContexts = displayedUserMessage.contexts;315+ const userMessageCopyText = row.message.text;
- @@ -697,15 +749,8 @@749+ .filter((entry) => entry.matchIndex >= 0)750+ .toSorted((left, right) => left.matchIndex - right.matchIndex);697751 let cursor = 0;698752699- for (const context of props.terminalContexts) {700- const label = formatInlineTerminalContextLabel(context.header);701- const matchIndex = props.text.indexOf(label, cursor);702- if (matchIndex === -1) {703- inlineNodes.length = 0;704- break;705- }706- if (matchIndex > cursor) {707- inlineNodes.push(708- <span key={`user-terminal-context-inline-before:${context.header}:${cursor}`}>709- {props.text.slice(cursor, matchIndex)}710- </span>,711- );753+ if (matchedInlineEntries.length === inlineEntries.length) {754+ for (const entry of matchedInlineEntries) {755+ const matchIndex = props.text.indexOf(entry.label, cursor);756+ if (matchIndex < cursor) {
juliusmarminge closed this
Sign in to join this conversation.


Important
Review skipped#
Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the
.coderabbit.yamlfile in this repository. To trigger a single review, invoke the@coderabbitai reviewcommand.⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID:
97c9f967-5ebb-46d6-b368-1888a6c8f395You can disable this status message by setting the
reviews.review_statustofalsein the CodeRabbit configuration file.Use the checkbox below for a quick retry:
✨ Finishing Touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.
❤️ Share