Skip to content
Source
Sign inSign up
pingdotgg/t3code

Add file preview comments and task toggles #3115

Mergedjuliusmarmingemerged 3 commits intomain fromrefs/pull/3115/headmerged by juliusmarminge View on GitHub

juliusmarmingecommented

Summary

  • Added interactive task-list checkboxes in markdown previews, including draft updates when tasks are toggled.
  • Added file preview comment annotations with local draft comments, inline comment pills in the composer, and support for adding/removing review comments.
  • Expanded file preview behavior for editable files, including editor dismissal handling, compact open-in-editor controls, and preview mode helpers.
  • Added unit and browser tests for markdown task toggles, file comment annotation behavior, composer review comment pills, and preview utilities.

Testing

  • vp check
  • vp run typecheck
  • vp run lint
  • vp test
  • Not run: additional manual browser verification beyond automated browser tests

Note

Medium Risk Touches composer send/persistence (draft version bump), optimistic file writes for markdown edits, and a vendored diff/editor patch—user data loss risk is low but behavior regressions in review UX or saves are plausible.

Overview Adds line-level review comments from the diff panel and editable file preview into the chat composer as pending chips, then serializes them into outgoing prompts (with restore on send failure). Review-comment parsing/formatting now supports non-diff fenced context (e.g. file snippets), safer attribute escaping, and matching display on web and mobile.

File preview gains gutter annotations with draft/submit flows, a rendered markdown mode for .md/.mdx, and clickable task-list checkboxes that debounce-save back to the file. ChatMarkdown wires task toggles via marker offsets; timeline cards show source fences instead of diff UI when appropriate.

Composer drafts persist reviewComments (storage v7 → v8). A @pierre/diffs patch keeps line selection/gutter utilities enabled while files stay content-editable.

Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit f78ff1e59ecad6ebf08f33cacb9d2a969a3b08b4. Bugbot is set up for automated code reviews on this repo. Configure [here](https://www.cursor.com/dashboard/bugbot).

Note

Add inline file preview comments and markdown task list toggles to file preview panel

  • Adds inline comment annotations to the editable file viewer: users can select a line range, enter comment text, and persist it into the composer draft store via addReviewComment/removeReviewComment
  • Introduces AnnotatableFileDiff to replace FileDiff in DiffPanel, enabling the same inline comment flow for diff views with gutter click or line selection
  • Adds a rendered markdown view in FilePreviewPanel with interactive task list checkboxes that persist changes to disk via RenderedMarkdownSurface
  • Pending review comments appear in the composer as removable chips (ComposerPendingReviewComments) and are appended to the outgoing prompt text; on send failure they are restored to the draft
  • Extends reviewCommentContext serialization to support non-diff fenced content (file previews), escape angle brackets in attributes, and infer fence language from file extension
  • Bumps composerDraftStore persistence version from 7 to 8 to store reviewComments in persisted draft state
  • Risk: the version bump will invalidate existing persisted composer drafts on upgrade
Macroscope summarized f78ff1e.
    1. coderabbitai[bot](GitHub profile, opens in a new tab)commented

      Important

      Review skipped

      Auto reviews are disabled on this repository. Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

      ⚙️ Run configuration

      Configuration used: Repository UI

      Review profile: CHILL

      Plan: Pro

      Run ID: 52800d07-51b8-403e-8c17-c6721e17f102

      You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

      Use the checkbox below for a quick retry:

      • 🔍 Trigger review
      ✨ Finishing Touches
      🧪 Generate unit tests (beta)
      • Create PR with unit tests
      • Commit unit tests in branch `t3code/707d8b1a`

      Comment `@coderabbitai help` to get the list of available commands and usage tips.
    2. github-actions[bot](GitHub profile, opens in a new tab) added labelsvouch:trusted

    3. Cursor Bugbot has reviewed your changes and found 1 potential issue.

      Autofix Details

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Stale markdown on task toggle
        • The onTaskListChange handler now reads the latest optimistic file contents via resolveProjectFileQueryData instead of using the potentially stale contents prop, ensuring subsequent toggles apply changes to the most recent text.

      Create PR

      Or push these changes by commenting:

      @cursor push a4c1d32aa4
      Preview (pingdotgg/t3code@a4c1d32aa4)
      diff --git a/apps/web/src/components/files/FilePreviewPanel.tsx b/apps/web/src/components/files/FilePreviewPanel.tsx
      --- a/apps/web/src/components/files/FilePreviewPanel.tsx
      +++ b/apps/web/src/components/files/FilePreviewPanel.tsx
      @@ -54,6 +54,7 @@
       import { FileSaveCoordinator } from "./fileSaveCoordinator";
       import {
         confirmProjectFileQueryData,
      +  resolveProjectFileQueryData,
         setProjectFileQueryData,
         useProjectFileQuery,
       } from "./projectFilesQueryState";
      @@ -446,8 +447,15 @@
               threadRef={threadRef}
               className="mx-auto max-w-4xl px-6 py-5"
               onTaskListChange={({ markerOffset, checked }) => {
      -          const nextContents = setMarkdownTaskChecked(contents, markerOffset, checked);
      -          if (nextContents === contents) return;
      +          const currentContents =
      +            resolveProjectFileQueryData(environmentId, cwd, relativePath, {
      +              relativePath,
      +              contents,
      +              byteLength: 0,
      +              truncated: false,
      +            })?.contents ?? contents;
      +          const nextContents = setMarkdownTaskChecked(currentContents, markerOffset, checked);
      +          if (nextContents === currentContents) return;
                 setProjectFileQueryData(environmentId, cwd, relativePath, nextContents);
                 saveCoordinator.change(nextContents);
               }}
      You can send follow-ups to the cloud agent here.
    4. github-actions[bot](GitHub profile, opens in a new tab)commented

      🚀 Expo continuous deployment is ready!

      • Project → t3-code
      • Platforms → android, ios
      • Scheme → t3code-preview
       🤖 Android🍎 iOS
      Fingerprint052dc86843f08d733f88b4c444db61397f6e511756f0ff9f61b9906d203c2fea265e3f9507332117
      Build DetailsBuild Permalink
      DetailsDistribution: INTERNAL
      Build profile: preview:dev
      Runtime version: 052dc86843f08d733f88b4c444db61397f6e5117
      App version: 0.1.0
      Git commit: 8fee8d380395cc13bb037ca095d34e3b17e9c0cf
      Build Permalink
      DetailsDistribution: INTERNAL
      Build profile: preview:dev
      Runtime version: 56f0ff9f61b9906d203c2fea265e3f9507332117
      App version: 0.1.0
      Git commit: 8fee8d380395cc13bb037ca095d34e3b17e9c0cf
      Update DetailsUpdate Permalink
      DetailsBranch: pr-3115
      Runtime version: 052dc86843f08d733f88b4c444db61397f6e5117
      Git commit: 8fee8d380395cc13bb037ca095d34e3b17e9c0cf
      Update Permalink
      DetailsBranch: pr-3115
      Runtime version: 56f0ff9f61b9906d203c2fea265e3f9507332117
      Git commit: 8fee8d380395cc13bb037ca095d34e3b17e9c0cf
      Update QR
    5. Approvability

      Verdict: Needs human review

      1 blocking correctness issue found. Diff is too large for automated approval analysis. A human reviewer should evaluate this PR.

      You can customize Macroscope's approvability policy. [Learn more](https://docs.macroscope.com/approvability#example-custom-eligibility-rules).
    6. @@ -0,0 +46,21 @@
      46+ filePath="src/app.ts"
      47+ sectionId="turn:2"
      48+ sectionTitle="Turn 2"
      49+ composerDraftTarget={threadRef}
      50+ renderHeaderPrefix={() => null}
      51+ options={{
      52+ diffStyle: "unified",
      53+ lineDiffType: "none",
      54+ themeType: "light",
      55+ }}
      56+ />
      57+ );
      58+}
      59+
      60+async function getRenderedDiff() {
      61+ return vi.waitFor(() => {
      62+ const element = document.querySelector<HTMLElement>("diffs-container");
      63+ expect(element?.shadowRoot).not.toBeNull();
      64+ return element!;
      65+ });
      66+}
      macroscopeapp[bot](GitHub profile, opens in a new tab)commented

      🟢 Low diffs/AnnotatableFileDiff.browser.tsx:60

      When querySelector("diffs-container") returns null, the assertion expect(element?.shadowRoot).not.toBeNull() passes anyway because undefined !== null. This causes getRenderedDiff() to return null (via element!) instead of retrying, leading to downstream failures when the test accesses .shadowRoot on the returned value. Consider asserting that element itself is not null before checking its shadowRoot.

      async function getRenderedDiff() {
        return vi.waitFor(() => {
          const element = document.querySelector<HTMLElement>("diffs-container");
      -    expect(element?.shadowRoot).not.toBeNull();
      +    expect(element).not.toBeNull();
      +    expect(element!.shadowRoot).not.toBeNull();
          return element!;
        });
      }
      🚀 Reply "fix it for me" or copy this AI Prompt for your agent:
      In file @apps/web/src/components/diffs/AnnotatableFileDiff.browser.tsx around lines 60-66:
      
      When `querySelector("diffs-container")` returns `null`, the assertion `expect(element?.shadowRoot).not.toBeNull()` passes anyway because `undefined !== null`. This causes `getRenderedDiff()` to return `null` (via `element!`) instead of retrying, leading to downstream failures when the test accesses `.shadowRoot` on the returned value. Consider asserting that `element` itself is not null before checking its shadowRoot.
      
      Evidence trail:
      apps/web/src/components/diffs/AnnotatableFileDiff.browser.tsx lines 60-66 (REVIEWED_COMMIT): `getRenderedDiff()` uses `element?.shadowRoot` with `.not.toBeNull()` — optional chaining on null yields undefined, which passes `!== null`. Vitest toBeNull docs confirm it checks `=== null`. vi.waitFor retries until callback doesn't throw, so a passing assertion on a null element stops retries prematurely.
    7. Cursor Bugbot has reviewed your changes and found 1 potential issue.

      Fix All in Cursor

      Bugbot Autofix prepared a fix for the issue found in the latest run.

      • ✅ Fixed: Duplicate diff line annotations
        • Changed the lineAnnotations memo to merge draft annotation entries into an existing persisted annotation at the same side/lineNumber instead of blindly concatenating, matching the merge behavior used in FilePreviewPanel.beginComment.

      Create PR

      Or push these changes by commenting:

      @cursor push 03fc43d3b6
      Preview (pingdotgg/t3code@03fc43d3b6)
      diff --git a/apps/web/src/components/diffs/AnnotatableFileDiff.tsx b/apps/web/src/components/diffs/AnnotatableFileDiff.tsx
      --- a/apps/web/src/components/diffs/AnnotatableFileDiff.tsx
      +++ b/apps/web/src/components/diffs/AnnotatableFileDiff.tsx
      @@ -114,10 +114,25 @@
               }, []),
           [fileDiff, filePath, reviewComments, sectionId],
         );
      -  const lineAnnotations = useMemo(
      -    () => (draftAnnotation ? [...persistedAnnotations, draftAnnotation] : persistedAnnotations),
      -    [draftAnnotation, persistedAnnotations],
      -  );
      +  const lineAnnotations = useMemo(() => {
      +    if (!draftAnnotation) return persistedAnnotations;
      +    const existingIndex = persistedAnnotations.findIndex(
      +      (a) => a.side === draftAnnotation.side && a.lineNumber === draftAnnotation.lineNumber,
      +    );
      +    if (existingIndex < 0) {
      +      return [...persistedAnnotations, draftAnnotation];
      +    }
      +    return persistedAnnotations.map((annotation, index) =>
      +      index === existingIndex
      +        ? {
      +            ...annotation,
      +            metadata: {
      +              entries: [...annotation.metadata.entries, ...draftAnnotation.metadata.entries],
      +            },
      +          }
      +        : annotation,
      +    );
      +  }, [draftAnnotation, persistedAnnotations]);
       
         const removeAnnotationEntry = useCallback(
           (entryId: string) => {
      You can send follow-ups to the cloud agent here. Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit f78ff1e59ecad6ebf08f33cacb9d2a969a3b08b4. Configure [here](https://www.cursor.com/dashboard/bugbot).
      @@ -0,0 +173,21 @@
      173+ id,
      174+ sectionId,
      175+ sectionTitle,
      176+ filePath,
      177+ fileDiff,
      178+ range,
      179+ text: "",
      180+ });
      181+ if (!comment) return;
      182+
      183+ const draftEntry: DiffCommentAnnotationEntry = {
      184+ id,
      185+ kind: "draft",
      186+ range,
      187+ rangeLabel: comment.rangeLabel,
      188+ text: "",
      189+ };
      190+ setDraftAnnotation({
      191+ side: annotationSide(range),
      192+ lineNumber: range.end,
      193+ metadata: { entries: [draftEntry] },

      Duplicate diff line annotations

      Medium Severity

      When a diff line already has a persisted review annotation, starting another comment on that same line adds a separate draftAnnotation instead of appending to the existing gutter group. lineAnnotations then contains two entries for the same side and line number, which can duplicate or misplace inline comment UI compared to multiple saved comments on one line.

      Fix in Cursor Fix in Web
      Reviewed by [Cursor Bugbot](https://cursor.com/bugbot) for commit f78ff1e59ecad6ebf08f33cacb9d2a969a3b08b4. Configure [here](https://www.cursor.com/dashboard/bugbot).
    8. Bugbot Autofix prepared fixes for both issues found in the latest run.

      • ✅ Fixed: Fence regex splits comment text
        • Changed extractReviewCommentText and extractReviewCommentFence to find the last fence match in the body (instead of the first), so user comment text containing fenced code blocks no longer gets misinterpreted as the snippet fence.
      • ✅ Fixed: Diff annotations not restored
        • Added a useMemo that reads existing reviewComments from the composer draft store on mount and initializes lineAnnotations state with restored annotation entries, so inline diff annotations survive component remounts.

      Create PR

      Or push these changes by commenting:

      @cursor push b9dcabbc95
      Preview (pingdotgg/t3code@b9dcabbc95)
      diff --git a/apps/mobile/src/features/review/reviewCommentSelection.ts b/apps/mobile/src/features/review/reviewCommentSelection.ts
      --- a/apps/mobile/src/features/review/reviewCommentSelection.ts
      +++ b/apps/mobile/src/features/review/reviewCommentSelection.ts
      @@ -197,9 +197,20 @@
         return Number(value);
       }
       
      +function findLastFenceMatch(rawBody: string): RegExpMatchArray | null {
      +  const globalPattern = new RegExp(REVIEW_COMMENT_FENCE_PATTERN.source, "g");
      +  let last: RegExpMatchArray | null = null;
      +  let match: RegExpExecArray | null;
      +  while ((match = globalPattern.exec(rawBody)) !== null) {
      +    last = match;
      +  }
      +  return last;
      +}
      +
       function extractReviewCommentText(rawBody: string): string {
      -  const fenceIndex = rawBody.search(REVIEW_COMMENT_FENCE_PATTERN);
      -  const commentBody = fenceIndex >= 0 ? rawBody.slice(0, fenceIndex) : rawBody;
      +  const lastMatch = findLastFenceMatch(rawBody);
      +  const commentBody =
      +    lastMatch && lastMatch.index !== undefined ? rawBody.slice(0, lastMatch.index) : rawBody;
         return commentBody.trim();
       }
       
      @@ -207,7 +218,7 @@
         language: string;
         contents: string;
       } {
      -  const match = rawBody.match(REVIEW_COMMENT_FENCE_PATTERN);
      +  const match = findLastFenceMatch(rawBody);
         return {
           language: match?.[2]?.trim() || "diff",
           contents: match?.[3] ?? "",
      
      diff --git a/apps/web/src/components/diffs/AnnotatableFileDiff.tsx b/apps/web/src/components/diffs/AnnotatableFileDiff.tsx
      --- a/apps/web/src/components/diffs/AnnotatableFileDiff.tsx
      +++ b/apps/web/src/components/diffs/AnnotatableFileDiff.tsx
      @@ -5,10 +5,10 @@
         SelectedLineRange,
       } from "@pierre/diffs";
       import { FileDiff, type FileDiffProps } from "@pierre/diffs/react";
      -import { useCallback, useState, type ReactNode } from "react";
      +import { useCallback, useMemo, useState, type ReactNode } from "react";
       
       import { type DraftId, useComposerDraftStore } from "~/composerDraftStore";
      -import { buildDiffReviewComment } from "~/reviewCommentContext";
      +import { buildDiffReviewComment, resolveReviewCommentDiffPlacement } from "~/reviewCommentContext";
       import type { ScopedThreadRef } from "@t3tools/contracts";
       
       import { LocalCommentAnnotation } from "../files/LocalCommentAnnotation";
      @@ -50,8 +50,42 @@
         const addReviewComment = useComposerDraftStore((store) => store.addReviewComment);
         const removeReviewComment = useComposerDraftStore((store) => store.removeReviewComment);
         const [selectedRange, setSelectedRange] = useState<SelectedLineRange | null>(null);
      -  const [lineAnnotations, setLineAnnotations] = useState<DiffCommentLineAnnotation[]>([]);
       
      +  const restoredAnnotations = useMemo((): DiffCommentLineAnnotation[] => {
      +    const draft = useComposerDraftStore.getState().getComposerDraft(composerDraftTarget);
      +    if (!draft) return [];
      +    const matching = draft.reviewComments.filter((c) => c.sectionId === sectionId);
      +    const annotations: DiffCommentLineAnnotation[] = [];
      +    for (const comment of matching) {
      +      const placement = resolveReviewCommentDiffPlacement(fileDiff, comment);
      +      if (!placement) continue;
      +      const entry: DiffCommentAnnotationEntry = {
      +        id: comment.id,
      +        kind: "comment",
      +        range: { start: placement.lineNumber, end: placement.lineNumber, side: placement.side },
      +        rangeLabel: comment.rangeLabel,
      +        text: comment.text,
      +      };
      +      const existing = annotations.find(
      +        (a) => a.side === placement.side && a.lineNumber === placement.lineNumber,
      +      );
      +      if (existing) {
      +        existing.metadata.entries.push(entry);
      +      } else {
      +        annotations.push({
      +          side: placement.side,
      +          lineNumber: placement.lineNumber,
      +          metadata: { entries: [entry] },
      +        });
      +      }
      +    }
      +    return annotations;
      +    // eslint-disable-next-line react-hooks/exhaustive-deps
      +  }, [composerDraftTarget, sectionId, fileDiff]);
      +
      +  const [lineAnnotations, setLineAnnotations] =
      +    useState<DiffCommentLineAnnotation[]>(restoredAnnotations);
      +
         const removeAnnotationEntry = useCallback(
           (entryId: string) => {
             setSelectedRange(null);
      
      diff --git a/apps/web/src/reviewCommentContext.ts b/apps/web/src/reviewCommentContext.ts
      --- a/apps/web/src/reviewCommentContext.ts
      +++ b/apps/web/src/reviewCommentContext.ts
      @@ -75,9 +75,20 @@
         return Number(value);
       }
       
      +function findLastFenceMatch(rawBody: string): RegExpMatchArray | null {
      +  const globalPattern = new RegExp(REVIEW_COMMENT_FENCE_PATTERN.source, "g");
      +  let last: RegExpMatchArray | null = null;
      +  let match: RegExpExecArray | null;
      +  while ((match = globalPattern.exec(rawBody)) !== null) {
      +    last = match;
      +  }
      +  return last;
      +}
      +
       function extractReviewCommentText(rawBody: string): string {
      -  const fenceIndex = rawBody.search(REVIEW_COMMENT_FENCE_PATTERN);
      -  const commentBody = fenceIndex >= 0 ? rawBody.slice(0, fenceIndex) : rawBody;
      +  const lastMatch = findLastFenceMatch(rawBody);
      +  const commentBody =
      +    lastMatch && lastMatch.index !== undefined ? rawBody.slice(0, lastMatch.index) : rawBody;
         return commentBody.trim();
       }
       
      @@ -85,7 +96,7 @@
         language: string;
         contents: string;
       } {
      -  const match = rawBody.match(REVIEW_COMMENT_FENCE_PATTERN);
      +  const match = findLastFenceMatch(rawBody);
         return {
           language: match?.[2]?.trim() || "diff",
           contents: match?.[3] ?? "",
      @@ -400,6 +411,22 @@
         };
       }
       
      +export function resolveReviewCommentDiffPlacement(
      +  fileDiff: FileDiffMetadata,
      +  comment: ReviewCommentContext,
      +): { side: "additions" | "deletions"; lineNumber: number } | null {
      +  const lines = buildDiffReviewLines(fileDiff);
      +  const line = lines[comment.endIndex];
      +  if (!line) return null;
      +  if (line.change === "delete") {
      +    return line.oldLineNumber !== null
      +      ? { side: "deletions", lineNumber: line.oldLineNumber }
      +      : null;
      +  }
      +  const lineNumber = line.newLineNumber ?? line.oldLineNumber;
      +  return lineNumber !== null ? { side: "additions", lineNumber } : null;
      +}
      +
       export function buildReviewCommentRenderablePatch(comment: ReviewCommentContext): string {
         if ((comment.fenceLanguage ?? "diff") !== "diff") {
           return "";
      You can send follow-ups to the cloud agent here.
    9. juliusmarminge merged thisc2ca9de

    10. juliusmarminge closed this

Sign in to join this conversation.