You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Annotate PDFs in the Files panel and send all the comments to the agent at once #369
i am often wanting to annoate or leave comments for ai agents to make edits of pdfs (slide decks or manuscripts) while I read them in the side panel in t3code and would like a way to natively add comments and annocations like you can for websites and send them all in.
What exists today
Files panel PDF viewer:apps/web/src/components/files/PdfViewer.tsx, built on pdf.js (pdfDocument.ts, pdfLayout.ts). It renders PDFs but has no comments.
Code files in the same panel: these have line comments (fileCommentAnnotations.ts, FilePreviewPanel.tsx, diffs/AnnotatableCodeView.tsx). The comments become composer context chips (lib/composerContextRecords.ts, ContextChip.tsx).
Browser preview: pages can be annotated by picking an element (lib/previewAnnotation.ts, preview/PreviewPanel.tsx, browser/annotationTheme.ts; desktop only). Upstream fix(desktop): PDFs in the preview can be annotated pingdotgg/t3code#24022 lets a PDF opened in the desktop Browser preview be annotated that way, but that path has no page or text anchors, and it doesn't work on web.
Goal
While reading a PDF (a slide deck or a manuscript) in the Files side panel, the user can:
mark a spot, a region or selected text on a page;
type a comment for each mark;
see the marks on the pages;
send all of them to the agent in one message.
The agent gets enough to act on each comment without guessing: the file path, the page number, the quoted text or region, and the comment. For a slide, it may also need a picture of the marked area. It should work on web and desktop, and locally and remotely.
Out of scope
Mobile.
Writing annotations into the PDF file itself.
Collaborative or persisted review threads, unless the design shows they are needed.
Next step
A designer researches and writes the plan here, with the strategy decisions and the done criteria. Implementation starts after the 2026-11-11 upstream sync (#368) lands, because that sync rewrites many of the chat and composer files this touches.
Design (Designer, 2026-11-11), planned against the sync target d2c25950b4
Problem
The Files panel shows PDFs, but the user has no way to mark a page and leave the agent a comment on it. Code files in the same panel already support comments: each saved comment becomes a composer chip, and every chip goes out together when the user sends the message. PDFs should work the same way.
Findings (from upstream at d2c25950b4)
Code-file comments are already "collect, then send all at once." In FilePreviewPanel.tsxEditableFileSurface, saving a comment calls addReviewComment(composerDraftTarget, buildFileReviewComment(...)) (apps/web/src/reviewCommentContext.ts). The comment becomes a review-comment chip, and the composer's normal Send delivers every chip in one message. Removing a chip or the comment removes both.
The review-comment wire record already carries what the agent needs.ReviewCommentContextRecord (packages/contracts/src/composerContext.ts) has filePath, rangeLabel, sectionTitle, text (the comment, up to 16k), diff (quoted content, up to 32k) and fenceLanguage. formatComposerContextProviderPayload (packages/shared/src/composerContextReferences.ts) sends it to the provider as file:, range:, section:, comment: and the quoted block.
Draft review comments persist with the composer draft.composerDraftStore.ts stores reviewComments: Array(ReviewCommentContextSchema), so they survive a reload and are cleared when the message is sent.
Images already have a path to the agent. Browser-preview annotations add their crop as an ordinary composer image attachment (PreviewView.tsx: addImage(threadRef, image)), which uploads through the existing attachment flow and works remotely.
PdfViewer.tsx draws each page as a canvas plus a pdf.js TextLayer. Native text selection therefore already works, and a crop can be read from the canvas that is already drawn. Pages are virtualized.
Trap:BrowserDocumentFrame.tsxPdfDocumentRevision uses Chromium's built-in PDF iframe on web, outside Electron and iOS. pdf.js runs only on desktop and iOS. Our code cannot draw on or read from the built-in viewer.
The browser-preview annotation look comes from theme variables.annotationTheme.ts reads --primary, --ring, --popover and others for the Electron preview overlay. A PDF overlay inside the web app can use the same variables directly through CSS classes; it needs no new theme object.
Strategy decisions
PDF marks are review comments. No new context kind, no contracts change, no server change. Each mark becomes a ReviewCommentContext built by a new buildPdfReviewComment:
sectionId: "pdf:<relative path>"
sectionTitle: "PDF comment"
filePath: the relative path
startIndex = endIndex = page - 1
rangeLabel: p3 for a text mark; p3, region x 12–60%, y 40–55% for a region or spot mark
text: the comment
diff: the quoted text (empty for a region)
fenceLanguage: "text"
The agent receives the file, page, quote or region, and comment through the existing formatter.
Mark geometry lives only in the draft. Add one optional client field, pdfMark: { page, x, y, width, height } (fractions of the page, 0–1), to ReviewCommentContextSchema in reviewCommentContext.ts. That is one optional line in an upstream file; it persists with the draft and never crosses the wire. rangeLabel is derived from it in the builder, so the geometry has one owner.
The composer draft is the only store for marks. The overlay draws the draft's review comments whose sectionId is pdf:<this path>. This one source handles every case:
removing a chip removes its mark;
after Send the draft is cleared, so the marks disappear;
after a reload the draft is restored, so the marks come back.
Code files need local lineAnnotations state only because the Pierre editor owns its own annotations; the PDF overlay does not need that.
Marking (three kinds, two gestures):
Selected text: select text normally in the text layer. On mouse-up inside one page, a comment form opens at the selection. The quote is selection.toString(); the rectangle is the selection's bounding box on that page. A selection that crosses pages is clamped to the page where it started.
Region: a toolbar toggle, "Mark area" (crosshair cursor; Escape or a second press turns it off). Dragging on a page draws a rectangle.
Spot: in area mode, a click or a drag under about 8 px becomes a spot: a fixed box about 12% of page width centred on the point, drawn as a pin.
Comment form: reuse DiffCommentAnnotation, with its draft and comment kinds and Cancel, Comment and Delete, in a small absolutely positioned popover beside the mark. One draft form is open at a time, as with code files. Editing an existing comment means clicking its mark: the form opens with the old text, and saving replaces the comment under the same id.
How marks look: an absolutely positioned layer over each page. Each mark is a box with a --primary border at low opacity, or a pin for a spot, plus a small number badge in page order. Text marks use their bounding box, not one rectangle per line (ponytail: multi-line selections highlight their whole bounding box; draw one rectangle per line if this looks wrong in use). No animation.
Cropped image: region and spot marks attach a crop; text marks do not.
The crop is cut from the page canvas that is already drawn, with its long edge capped at 1024 px.
It is encoded as PNG with canvas.toBlob and added with addImage(target, { id: <mark id>, ... }), as preview annotations do. The existing upload handles local and remote connections, and removing the comment also removes the image.
Slides tend to use region marks, so they get pictures. Manuscripts tend to use text marks, so their messages stay small.
If the canvas is not drawn yet, or the crop fails, keep the comment without the image and show the same toast that preview annotations use.
Send all at once = the composer's normal Send. Every saved comment is already a chip in the active thread's composer, so the message carries all of them in one turn, ordered by when each chip was added. No extra "send all" button. The toolbar shows "N comments" so the user can see the count.
When the file changes: marks are keyed by path, not by revision. They stay in the draft and are redrawn on the new revision at the same page fractions. A mark whose page no longer exists is not drawn, but its chip stays visible and removable. No re-anchoring (ponytail: add one only if real edit loops show drift).
Web uses pdf.js when comments are possible.BrowserDocumentFrame and PdfDocumentRevision get an optional comments prop. When it is set (a project PDF in the Files panel with a composer target), they always use PdfViewer instead of the built-in iframe. Attachment previews and HTML renders keep today's behavior. This is the only way to get page and text anchors on web.
Fork shape: almost all the code goes in one new fork-owned file, apps/web/src/components/files/PdfComments.tsx, which holds the page overlay, the area-mode toggle and count, gesture handling, the crop, and buildPdfReviewComment. Hook points in upstream files:
PdfViewer.tsx: an optional comments prop, one overlay element per page, one slot in the toolbar;
BrowserDocumentFrame.tsx: pass the prop through and pick pdf.js when it is set;
FilePreviewPanel.tsx: build the prop from composerDraftTarget and the relative path in the workspace PDF preview;
reviewCommentContext.ts: the optional pdfMark field.
Surfaces
Web and desktop: both use the same PdfViewer path; decision 10 makes web match desktop.
Local and remote: no new RPC. Text and coordinates travel in the existing context record, and crops use the existing attachment upload.
Mobile: out of scope.
Providers: Codex and Claude both accept image attachments, and the text record works for every provider.
Keybindings, command palette, settings: nothing new. Escape leaves area mode and cancels an open form; no global binding is needed.
Agents (MCP): nothing new. Marking a PDF is a human reading task.
Reverse states: a comment is removed with its form's Delete or by removing its chip; area mode turns off with Escape or the toggle; marks are visible as numbered boxes.
Docs: add one sentence on PDF comments to the user guide section on the Files panel, if one exists.
Out of scope
Writing annotations into the PDF, shared or persisted review threads, mobile, PDF comments on chat attachments, re-anchoring marks after edits, one rectangle per line for text marks.
Tests (only where behavior can break)
buildPdfReviewComment: one table test covering a text mark (quote set, label pN), a region mark (no quote, label with percentages) and a spot, with the label derived from pdfMark. Put it beside the existing reviewCommentContext tests if there are any.
One PdfViewer.browser.test.tsx case: with the comments prop, a draft review comment carrying pdfMark draws a mark on its page, and deleting it removes the chip. Extend the existing file.
The draft-store round trip already covers ReviewCommentContextSchema, so add a pdfMark row only if that test enumerates fields.
Done when
In the Files panel on desktop and on web, the user can comment on selected text, on a dragged region and on a spot of a PDF page. The marks show numbered on the page and as chips in the composer.
A comment can be edited or deleted from its mark, and removing its chip removes the mark.
One Send delivers all the comments in one message. For each comment the agent sees file:, range: pN…, section: PDF comment, the comment, and the quote for text marks; region and spot marks also attach a cropped PNG of at most 1024 px.
After Send the marks clear; after a reload they come back from the draft; after the file changes they remain at the same page fractions.
It works against a remote environment with no change to contracts or the server.
The tests above pass and vp run check:changed is clean. One integrated pass in the in-app browser (test-t3-app), with before and after captures, on a slide PDF and a manuscript PDF.
Implemented #369 and committed locally as f979db12769181a4439b76d0d17e162601ef3968. The working tree is clean. No push or PR.
File by file:
PdfComments.tsx: selected-text, region, and spot marking; numbered markers; comment editing and deletion; area toggle, Escape cancellation, and comment count. Region and spot comments attach PNG crops capped at 1024 px.
composerDraftStore.ts: deleting a PDF comment also removes its crop.
PdfComments.test.ts: one table test covering page, quote, region/spot labels, and image decisions.
PdfViewer.browser.test.tsx: one new case covering text and spot marks, chips, markers, crop creation, and deletion.
docs/user/composer.md: brief PDF commenting guidance.
The only additional hook beyond the named files is crop cleanup in composerDraftStore.ts. This ensures deleting a chip removes its image even after the viewer closes. Contracts and server code are unchanged.
Validation:
Focused tests and neighbours: 8 files, 148 tests passed.
Final builder, browser, and React Compiler checks: 3 passed.
Final apps/web typecheck and targeted lint: passed.
check:changed ran once. Formatting, lint, knip 1/2, affected-package typechecks, and its 128 tests passed. React Compiler initially failed; that defect was fixed and its focused check passed afterward. Knip 2/2 retained the known failure with 81 existing unused exports.
The commit hook hit that same knip failure after passing formatting and lint. The local commit used a one-command hook bypass.
Unverified: the real-app pass you reserved, including remote sending, reload restoration, and visual placement on slide and manuscript PDFs. No dev server was started.
The probe reproduced the same flushSync warning for both code-file and PDF comments. Both use the existing composer path: the controlled editor update runs setContent in a layout effect, which creates a Tiptap React node view that calls flushSync. That path and the code-file call site predate this PR, so I’m leaving it unchanged as requested.
Activity
tannerpolley commentedon Nov 11, 2026
Design (Designer, 2026-11-11), planned against the sync target
d2c25950b4Problem
The Files panel shows PDFs, but the user has no way to mark a page and leave the agent a comment on it. Code files in the same panel already support comments: each saved comment becomes a composer chip, and every chip goes out together when the user sends the message. PDFs should work the same way.
Findings (from upstream at
d2c25950b4)FilePreviewPanel.tsxEditableFileSurface, saving a comment callsaddReviewComment(composerDraftTarget, buildFileReviewComment(...))(apps/web/src/reviewCommentContext.ts). The comment becomes areview-commentchip, and the composer's normal Send delivers every chip in one message. Removing a chip or the comment removes both.review-commentwire record already carries what the agent needs.ReviewCommentContextRecord(packages/contracts/src/composerContext.ts) hasfilePath,rangeLabel,sectionTitle,text(the comment, up to 16k),diff(quoted content, up to 32k) andfenceLanguage.formatComposerContextProviderPayload(packages/shared/src/composerContextReferences.ts) sends it to the provider asfile:,range:,section:,comment:and the quoted block.composerDraftStore.tsstoresreviewComments: Array(ReviewCommentContextSchema), so they survive a reload and are cleared when the message is sent.PreviewView.tsx:addImage(threadRef, image)), which uploads through the existing attachment flow and works remotely.PdfViewer.tsxdraws each page as a canvas plus a pdf.jsTextLayer. Native text selection therefore already works, and a crop can be read from the canvas that is already drawn. Pages are virtualized.BrowserDocumentFrame.tsxPdfDocumentRevisionuses Chromium's built-in PDF iframe on web, outside Electron and iOS. pdf.js runs only on desktop and iOS. Our code cannot draw on or read from the built-in viewer.annotationTheme.tsreads--primary,--ring,--popoverand others for the Electron preview overlay. A PDF overlay inside the web app can use the same variables directly through CSS classes; it needs no new theme object.Strategy decisions
PDF marks are review comments. No new context kind, no contracts change, no server change. Each mark becomes a
ReviewCommentContextbuilt by a newbuildPdfReviewComment:sectionId: "pdf:<relative path>"sectionTitle: "PDF comment"filePath: the relative pathstartIndex = endIndex = page - 1rangeLabel:p3for a text mark;p3, region x 12–60%, y 40–55%for a region or spot marktext: the commentdiff: the quoted text (empty for a region)fenceLanguage: "text"The agent receives the file, page, quote or region, and comment through the existing formatter.
Mark geometry lives only in the draft. Add one optional client field,
pdfMark: { page, x, y, width, height }(fractions of the page, 0–1), toReviewCommentContextSchemainreviewCommentContext.ts. That is one optional line in an upstream file; it persists with the draft and never crosses the wire.rangeLabelis derived from it in the builder, so the geometry has one owner.The composer draft is the only store for marks. The overlay draws the draft's review comments whose
sectionIdispdf:<this path>. This one source handles every case:Code files need local
lineAnnotationsstate only because the Pierre editor owns its own annotations; the PDF overlay does not need that.Marking (three kinds, two gestures):
selection.toString(); the rectangle is the selection's bounding box on that page. A selection that crosses pages is clamped to the page where it started.Comment form: reuse
DiffCommentAnnotation, with itsdraftandcommentkinds and Cancel, Comment and Delete, in a small absolutely positioned popover beside the mark. One draft form is open at a time, as with code files. Editing an existing comment means clicking its mark: the form opens with the old text, and saving replaces the comment under the same id.How marks look: an absolutely positioned layer over each page. Each mark is a box with a
--primaryborder at low opacity, or a pin for a spot, plus a small number badge in page order. Text marks use their bounding box, not one rectangle per line (ponytail:multi-line selections highlight their whole bounding box; draw one rectangle per line if this looks wrong in use). No animation.Cropped image: region and spot marks attach a crop; text marks do not.
canvas.toBloband added withaddImage(target, { id: <mark id>, ... }), as preview annotations do. The existing upload handles local and remote connections, and removing the comment also removes the image.Send all at once = the composer's normal Send. Every saved comment is already a chip in the active thread's composer, so the message carries all of them in one turn, ordered by when each chip was added. No extra "send all" button. The toolbar shows "N comments" so the user can see the count.
When the file changes: marks are keyed by path, not by revision. They stay in the draft and are redrawn on the new revision at the same page fractions. A mark whose page no longer exists is not drawn, but its chip stays visible and removable. No re-anchoring (
ponytail:add one only if real edit loops show drift).Web uses pdf.js when comments are possible.
BrowserDocumentFrameandPdfDocumentRevisionget an optionalcommentsprop. When it is set (a project PDF in the Files panel with a composer target), they always usePdfViewerinstead of the built-in iframe. Attachment previews and HTML renders keep today's behavior. This is the only way to get page and text anchors on web.Fork shape: almost all the code goes in one new fork-owned file,
apps/web/src/components/files/PdfComments.tsx, which holds the page overlay, the area-mode toggle and count, gesture handling, the crop, andbuildPdfReviewComment. Hook points in upstream files:PdfViewer.tsx: an optionalcommentsprop, one overlay element per page, one slot in the toolbar;BrowserDocumentFrame.tsx: pass the prop through and pick pdf.js when it is set;FilePreviewPanel.tsx: build the prop fromcomposerDraftTargetand the relative path in the workspace PDF preview;reviewCommentContext.ts: the optionalpdfMarkfield.Surfaces
PdfViewerpath; decision 10 makes web match desktop.Out of scope
Writing annotations into the PDF, shared or persisted review threads, mobile, PDF comments on chat attachments, re-anchoring marks after edits, one rectangle per line for text marks.
Tests (only where behavior can break)
buildPdfReviewComment: one table test covering a text mark (quote set, labelpN), a region mark (no quote, label with percentages) and a spot, with the label derived frompdfMark. Put it beside the existingreviewCommentContexttests if there are any.PdfViewer.browser.test.tsxcase: with thecommentsprop, a draft review comment carryingpdfMarkdraws a mark on its page, and deleting it removes the chip. Extend the existing file.ReviewCommentContextSchema, so add apdfMarkrow only if that test enumerates fields.Done when
file:,range: pN…,section: PDF comment, the comment, and the quote for text marks; region and spot marks also attach a cropped PNG of at most 1024 px.vp run check:changedis clean. One integrated pass in the in-app browser (test-t3-app), with before and after captures, on a slide PDF and a manuscript PDF.tannerpolley commentedon Nov 11, 2026
T3 Code status: Unavailable
Issue: #369 Annotate PDFs in the Files panel and send all the comments to the agent at once
Thread: thread:delegated-task:command%3Amcp%3A5fac60b4-d81c-48fd-acaa-8a46bf2219d0%3Adelegate-task%3Abuild-369-pdf-comments
Model: gpt-6.1-sol
Branch: issue-369-annotate-pdfs-in-the-files-panel-and
Updated: 2026-11-23T19:34:37.674Z
tannerpolley commentedon Nov 11, 2026
T3 Code closeout: done
Issue: #369 Annotate PDFs in the Files panel and send all the comments to the agent at once
Thread: thread:delegated-task:command%3Amcp%3A5fac60b4-d81c-48fd-acaa-8a46bf2219d0%3Adelegate-task%3Abuild-369-pdf-comments
Model: gpt-6.1-sol
Branch: issue-369-annotate-pdfs-in-the-files-panel-and
Completed: 2026-11-11T21:42:01.462Z
Implemented #369 and committed locally as
f979db12769181a4439b76d0d17e162601ef3968. The working tree is clean. No push or PR.File by file:
PdfComments.tsx: selected-text, region, and spot marking; numbered markers; comment editing and deletion; area toggle, Escape cancellation, and comment count. Region and spot comments attach PNG crops capped at 1024 px.PdfViewer.tsx: comment provider, toolbar slot, page overlays, and canvas readiness tracking.BrowserDocumentFrame.tsx: passes comment configuration through and selects pdf.js for comment-enabled project PDFs on web.FilePreviewPanel.tsx: supplies the composer target and relative PDF path.reviewCommentContext.ts: optional draft-onlypdfMarkgeometry.composerDraftStore.ts: deleting a PDF comment also removes its crop.PdfComments.test.ts: one table test covering page, quote, region/spot labels, and image decisions.PdfViewer.browser.test.tsx: one new case covering text and spot marks, chips, markers, crop creation, and deletion.docs/user/composer.md: brief PDF commenting guidance.The only additional hook beyond the named files is crop cleanup in
composerDraftStore.ts. This ensures deleting a chip removes its image even after the viewer closes. Contracts and server code are unchanged.Validation:
apps/webtypecheck and targeted lint: passed.check:changedran once. Formatting, lint, knip 1/2, affected-package typechecks, and its 128 tests passed. React Compiler initially failed; that defect was fixed and its focused check passed afterward. Knip 2/2 retained the known failure with 81 existing unused exports.Branch:
issue-369-annotate-pdfs-in-the-files-panel-andWorktree:
/home/tnnrpolley21/Workspaces/Applications/t3code/.worktrees/issue-369-annotate-pdfs-53eae53f8f1936ffUnverified: the real-app pass you reserved, including remote sending, reload restoration, and visual placement on slide and manuscript PDFs. No dev server was started.
tannerpolley commentedon Nov 11, 2026
T3 Code closeout: interrupted
Issue: #369 Annotate PDFs in the Files panel and send all the comments to the agent at once
Thread: thread:delegated-task:command%3Amcp%3A5fac60b4-d81c-48fd-acaa-8a46bf2219d0%3Adelegate-task%3Abuild-369-pdf-comments
Model: gpt-6.1-sol
Branch: issue-369-annotate-pdfs-in-the-files-panel-and
Completed: 2026-11-11T21:53:19.280Z
The probe reproduced the same
flushSyncwarning for both code-file and PDF comments. Both use the existing composer path: the controlled editor update runssetContentin a layout effect, which creates a Tiptap React node view that callsflushSync. That path and the code-file call site predate this PR, so I’m leaving it unchanged as requested.