From 9fae2cc22888b391d1935716f44b1d7447aa2b6e Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 23 Nov 2026 10:35:57 -0600 Subject: [PATCH 001/219] fix(web): accept TIFF Exif and GPS pointers stored as IFD type 13 (#41526) Co-authored-by: Julius Marminge --- .../AttachmentFilePreview.browser.test.tsx | 42 ++++++++++++++----- .../components/files/imageDecode.worker.ts | 3 +- 2 files changed, 33 insertions(+), 12 deletions(-) diff --git a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx index 77e339925c97e..10c013cc04723 100644 --- a/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx +++ b/apps/web/src/components/files/AttachmentFilePreview.browser.test.tsx @@ -514,14 +514,16 @@ describe("bounded binary previews", () => { } }); - it("keeps WhiteIsZero TIFF brightness and alpha with SubIFDs tags and rejects oversized metadata before decoding", async () => { + it("keeps WhiteIsZero TIFF brightness and alpha with SubIFDs and type-13 ExifIFD pointers and rejects invalid metadata before decoding", async () => { let bytes = new ArrayBuffer(0); + let exifEntry = 0; for (const { pixels, expected } of [ { pixels: [0, 255], expected: [255, 255, 255, 255, 0, 0, 0, 255] }, { pixels: [0, 255, 255, 0], expected: [255, 255, 255, 255, 0, 0, 0, 0] }, ]) { const samples = pixels.length / 2; - const start = samples === 2 ? 158 : 146; + const start = samples === 2 ? 170 : 158; + const exif = start + pixels.length; const tags = [ [256, 2], [257, 1], @@ -535,8 +537,10 @@ describe("bounded binary previews", () => { [284, 1], [330, 0, 13], ...(samples === 2 ? [[338, 2]] : []), + [34665, exif, 13], ]; - bytes = new ArrayBuffer(start + pixels.length); + exifEntry = 10 + (tags.length - 1) * 12; + bytes = new ArrayBuffer(exif + 8); const view = new DataView(bytes); view.setUint16(0, 0x4949); view.setUint16(2, 42, true); @@ -563,14 +567,30 @@ describe("bounded binary previews", () => { URL.revokeObjectURL(src); } } - new DataView(bytes).setUint32(14, 1_000_000, true); - const invalid = URL.createObjectURL(new Blob([bytes])); - try { - await expect( - decodeImagePreview(invalid, false, new AbortController().signal), - ).rejects.toThrow("metadata"); - } finally { - URL.revokeObjectURL(invalid); + for (const [mutate, message] of [ + [ + (view: DataView) => view.setUint16(exifEntry + 2, 3, true), + "Invalid TIFF metadata pointer.", + ], + [ + (view: DataView) => view.setUint32(exifEntry + 4, 2, true), + "Invalid TIFF metadata pointer.", + ], + [ + (view: DataView) => view.setUint32(14, 1_000_000, true), + "This TIFF has too much or truncated metadata.", + ], + ] as const) { + const copy = bytes.slice(0); + mutate(new DataView(copy)); + const invalid = URL.createObjectURL(new Blob([copy])); + try { + await expect( + decodeImagePreview(invalid, false, new AbortController().signal), + ).rejects.toThrow(message); + } finally { + URL.revokeObjectURL(invalid); + } } }); }); diff --git a/apps/web/src/components/files/imageDecode.worker.ts b/apps/web/src/components/files/imageDecode.worker.ts index 9cd3140308612..a3661b22612fb 100644 --- a/apps/web/src/components/files/imageDecode.worker.ts +++ b/apps/web/src/components/files/imageDecode.worker.ts @@ -34,7 +34,8 @@ function validateTiffMetadata(bytes: ArrayBuffer) { if (start + length > bytes.byteLength || allocation > 8 * 1024 * 1024) throw new PreviewError({ code: "tiff-metadata-truncated" }); if (tag === 0x8769 || tag === 0x8825) { - if (type !== 4 || values !== 1) throw new PreviewError({ code: "tiff-metadata-pointer" }); + if ((type !== 4 && type !== 13) || values !== 1) + throw new PreviewError({ code: "tiff-metadata-pointer" }); inspect(view.getUint32(entry + 8, littleEndian), depth + 1); } } From f58085a1c2e5bea0b020ee2d4d69f8768b7b228d Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 23 Nov 2026 10:38:17 -0600 Subject: [PATCH 002/219] fix(server): EPUBs with a percent-encoded package path extract their chapters (#41523) Co-authored-by: Julius Marminge --- .../server/src/provider/documentTextWorker.ts | 6 ++++- .../src/provider/userInputAttachments.test.ts | 27 +++++++++++++++++++ 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/apps/server/src/provider/documentTextWorker.ts b/apps/server/src/provider/documentTextWorker.ts index cf25d9c2f40d2..027029139a77e 100644 --- a/apps/server/src/provider/documentTextWorker.ts +++ b/apps/server/src/provider/documentTextWorker.ts @@ -838,7 +838,7 @@ async function* document(path: string, extension: string): AsyncGenerator [item.attrs.id, item.attrs.href]), diff --git a/apps/server/src/provider/userInputAttachments.test.ts b/apps/server/src/provider/userInputAttachments.test.ts index be2aab625142d..2e44f3501355c 100644 --- a/apps/server/src/provider/userInputAttachments.test.ts +++ b/apps/server/src/provider/userInputAttachments.test.ts @@ -741,6 +741,33 @@ describe("question answer paths", () => { ], absent: ["[Extracted text truncated"], }, + { + ext: "epub", + parts: { + "META-INF/container.xml": + '', + "My Book/book 1.opf": + '', + "My Book/ch1.xhtml": "

Percent-encoded rootfile chapter text.

", + }, + expected: ["Percent-encoded rootfile chapter text."], + absent: ["[Skipped document part", "[Extracted text truncated"], + }, + { + ext: "epub", + parts: { + "META-INF/container.xml": + '', + "OPS/book%201.opf": + '', + "ops/book 1.opf": + '', + "OPS/correct.xhtml": "

Correct primary chapter

", + "ops/other.xhtml": "

Wrong alternate chapter

", + }, + expected: ["Correct primary chapter"], + absent: ["Wrong alternate chapter", "[Skipped document part"], + }, ...[false, true].flatMap((bom) => [false, true].map((bigEndian) => { const encode = (source: string) => { From e2e8a49d972219e926f0940246208e82d129c87a Mon Sep 17 00:00:00 2001 From: Anton Metzner Rodriguez Date: Mon, 23 Nov 2026 18:08:22 +0100 Subject: [PATCH 003/219] fix(web): a PDF keeps its place when the pane is resized (#41537) Co-authored-by: Julius Marminge --- .../files/PdfViewer.browser.test.tsx | 33 +++++++++++++++++++ apps/web/src/components/files/PdfViewer.tsx | 15 +++++---- apps/web/src/components/files/pdfLayout.ts | 12 +++++++ 3 files changed, 54 insertions(+), 6 deletions(-) diff --git a/apps/web/src/components/files/PdfViewer.browser.test.tsx b/apps/web/src/components/files/PdfViewer.browser.test.tsx index ef339999e8d10..81bf3bcf91364 100644 --- a/apps/web/src/components/files/PdfViewer.browser.test.tsx +++ b/apps/web/src/components/files/PdfViewer.browser.test.tsx @@ -175,6 +175,39 @@ it("keeps the painted page while its width changes, then repaints it without a b } }); +it("keeps the page in view, with its painted canvas, when the pane narrows", async () => { + const page = { box: "0 0 612 792", rotate: 0, text: "BT /F1 24 Tf 30 700 Td (Text) Tj ET" }; + const url = URL.createObjectURL(testPdf(Array.from({ length: 6 }, () => page))); + try { + const container = document.createElement("div"); + container.style.cssText = "display:flex;width:500px;height:300px"; + await using screen = await render( + , + { container }, + ); + await expect.element(screen.getByText("4 / 6 pages"), { timeout: 10_000 }).toBeVisible(); + const region = screen.container.querySelector('[role="region"]')!; + const canvas = region.querySelector('canvas[aria-label="Page 4"]')!; + await vi.waitFor(() => expect(canvas.width).toBeGreaterThan(300)); + + container.style.width = "300px"; + await vi.waitFor(() => { + const top = region.getBoundingClientRect().top; + const box = canvas.getBoundingClientRect(); + expect(box.width).toBe(region.clientWidth - 32); + expect(box.top).toBeLessThanOrEqual(top); + expect(box.bottom).toBeGreaterThan(top); + }); + await expect.element(screen.getByText("4 / 6 pages")).toBeVisible(); + } finally { + URL.revokeObjectURL(url); + } +}); + it("jumps to the first hit while still counting and keeps later manual navigation", async () => { setup(4); const page = (text: string) => ({ diff --git a/apps/web/src/components/files/PdfViewer.tsx b/apps/web/src/components/files/PdfViewer.tsx index 31faf628fbeb9..9842a621c0302 100644 --- a/apps/web/src/components/files/PdfViewer.tsx +++ b/apps/web/src/components/files/PdfViewer.tsx @@ -27,6 +27,7 @@ import { pdfPageScrollTop, pdfPageText, pdfPageWidth, + pdfResizedScrollTop, pdfRestoredScrollTop, PDF_MAX_ZOOM, PDF_MIN_ZOOM, @@ -263,7 +264,7 @@ export default function PdfViewer(props: { const [zoom, setZoom] = useState(initialView.zoom); const [pageWidth, setPageWidth] = useState(612); const [viewport, setViewport] = useState({ width: 600, height: 800 }); - const [scrollTop, setScrollTop] = useState(0); + const [scrolled, setScrolled] = useState({ top: 0, width: 0, pdf }); const [query, setQuery] = useState(""); const [matches, setMatches] = useState([]); const [finding, setFinding] = useState(false); @@ -338,6 +339,9 @@ export default function PdfViewer(props: { }, []); const { scale, width } = pdfPageWidth(viewport.width, pageWidth, zoom); const offsets = pdfPageOffsets(ratios, width); + // A new page width moves every page, so the place in view has a new offset before the DOM scrolls. + const resized = pdf !== null && scrolled.pdf === pdf && scrolled.width !== width; + const scrollTop = resized ? pdfResizedScrollTop(ratios, scrolled, width) : scrolled.top; const current = currentPdfPage(offsets, ratios.length, scrollTop); const visible = visiblePdfPages(ratios, offsets, scrollTop, viewport.height); // Stable callbacks let page canvases survive scroll and find updates. @@ -374,7 +378,7 @@ export default function PdfViewer(props: { top: pdfRestoredScrollTop(ratios, width, initialView, savedPosition?.width), left: initialView.left, }); - setScrollTop(node.scrollTop); + setScrolled({ top: node.scrollTop, width, pdf }); saveView(node); }); // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Restore the saved PDF scroll position after the loaded document's page layout commits. @@ -392,7 +396,7 @@ export default function PdfViewer(props: { }; setZoom(value); }; - // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Restore the DOM scroll anchor after the new zoom width has committed to page layout. + // oxlint-disable-next-line t3code/no-unreasoned-state-sync -- Restore the DOM scroll anchor after a zoom or resize has committed the new page width. useLayoutEffect(() => { const anchor = zoomAnchor.current; zoomAnchor.current = null; @@ -402,7 +406,7 @@ export default function PdfViewer(props: { node.scrollTo({ top: offsets[anchor.page]! - 16 + (anchor.offset * width) / anchor.width, }); - } + } else if (resized) node.scrollTo({ top: scrollTop }); saveView(node, anchor !== null); }); const firstMatch = matches[0]; @@ -561,8 +565,7 @@ export default function PdfViewer(props: { tabIndex={0} className="relative min-h-0 min-w-0 w-full flex-1 overflow-auto scrollbar-gutter-stable bg-muted/40" onScroll={(event) => { - const top = event.currentTarget.scrollTop; - setScrollTop(top); + setScrolled({ top: event.currentTarget.scrollTop, width, pdf }); saveView(event.currentTarget); }} onKeyDown={(event) => { diff --git a/apps/web/src/components/files/pdfLayout.ts b/apps/web/src/components/files/pdfLayout.ts index 9292fcf583b46..0f48a112aa07d 100644 --- a/apps/web/src/components/files/pdfLayout.ts +++ b/apps/web/src/components/files/pdfLayout.ts @@ -66,6 +66,18 @@ export function pdfRestoredScrollTop( ); } +/** Where the place at `from.top` lands after the page width changes from `from.width`. */ +export function pdfResizedScrollTop( + ratios: readonly number[], + from: { top: number; width: number }, + width: number, +) { + const offsets = pdfPageOffsets(ratios, from.width); + const page = currentPdfPage(offsets, ratios.length, from.top); + const offset = from.top - (offsets[page]! - PDF_PAGE_GAP); + return pdfRestoredScrollTop(ratios, width, { page, offset }, from.width); +} + export function pdfPageText( items: readonly ({ str: string; hasEOL: boolean } | { type: string })[], ) { From 990412468340b8362f82610de0eae70a5171abb7 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 23 Nov 2026 11:09:55 -0600 Subject: [PATCH 004/219] fix(web): EPUBs with a percent-encoded package path open in the file preview (#41540) Co-authored-by: Julius Marminge --- .../components/files/FilePreviewPanel.test.ts | 26 +++++++++++++++++++ .../files/extendedDocumentPreview.ts | 5 ++-- 2 files changed, 29 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/files/FilePreviewPanel.test.ts b/apps/web/src/components/files/FilePreviewPanel.test.ts index b32a64fd18373..0b4d7dc46b49f 100644 --- a/apps/web/src/components/files/FilePreviewPanel.test.ts +++ b/apps/web/src/components/files/FilePreviewPanel.test.ts @@ -667,4 +667,30 @@ Third}`; expect(result.pages[1]!.html).toContain('src="data:image/png;base64,'); expect(result.pages[1]!.html).not.toMatch(/https:|script|alert/); }); + + it.each([ + ["percent-encoded", "My%20Book/book%201.opf", "My Book/book 1.opf", "My Book/one.xhtml"], + ["literal percent", "My%20Book/book.opf", "My%20Book/book.opf", "My%20Book/one.xhtml"], + ["malformed percent", "Book%ZZ/book.opf", "Book%ZZ/book.opf", "Book%ZZ/one.xhtml"], + ])( + "reads EPUB packages with %s rootfile paths", + async (_label, fullPath, packagePath, chapterPath) => { + const archive = new JSZip() + .file( + "META-INF/container.xml", + ``, + ) + .file( + packagePath, + '', + ) + .file( + chapterPath, + "First

Hello

", + ); + const result = await openEpub(archive); + if (result.type !== "document") throw new Error("Expected document"); + expect(result.pages).toEqual([{ title: "First", html: "

Hello

" }]); + }, + ); }); diff --git a/apps/web/src/components/files/extendedDocumentPreview.ts b/apps/web/src/components/files/extendedDocumentPreview.ts index d04f1c9882ee9..f57d9c59a101d 100644 --- a/apps/web/src/components/files/extendedDocumentPreview.ts +++ b/apps/web/src/components/files/extendedDocumentPreview.ts @@ -423,8 +423,9 @@ export async function openDocument( export async function openEpub(archive: JSZip): Promise { markupBytes = 0; const container = parseXml((await archive.file("META-INF/container.xml")?.async("string")) ?? ""); - const rootfile = find(container, "rootfile")[0]?.attrs["full-path"]; - if (!rootfile || !archive.file(rootfile)) throw new PreviewError({ code: "epub-no-package" }); + const fullPath = find(container, "rootfile")[0]?.attrs["full-path"] ?? ""; + const rootfile = [archivePath("", fullPath), fullPath].find((path) => path && archive.file(path)); + if (!rootfile) throw new PreviewError({ code: "epub-no-package" }); const packageRoot = parseXml(await archive.file(rootfile)!.async("string")); const manifest = new Map(find(packageRoot, "item").map((item) => [item.attrs.id, item])); const spine = find(packageRoot, "itemref"); From 7182abeeaab345f8a8e863a7835aead9b50ae57f Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 09:19:01 -0800 Subject: [PATCH 005/219] fix(client-runtime): command failures show the server's text for string defects (#41550) --- .../src/errors/translatable.test.ts | 21 +++++++++++++++++++ packages/client-runtime/src/state/runtime.ts | 4 +++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 packages/client-runtime/src/errors/translatable.test.ts diff --git a/packages/client-runtime/src/errors/translatable.test.ts b/packages/client-runtime/src/errors/translatable.test.ts new file mode 100644 index 0000000000000..de0339d9fd2d7 --- /dev/null +++ b/packages/client-runtime/src/errors/translatable.test.ts @@ -0,0 +1,21 @@ +import { describe, expect, it } from "@effect/vitest"; +import * as Cause from "effect/Cause"; +import * as Schema from "effect/Schema"; + +import { squashAtomCommandFailure } from "../state/runtime.ts"; +import { thrownErrorMessage } from "./translatable.ts"; + +const decodeDefect = Schema.decodeUnknownSync(Schema.Defect()); + +describe("thrownErrorMessage", () => { + it("shows the text of a string defect that came back over RPC", () => { + const defect = decodeDefect( + "RPC contract is registered but unavailable in the control plane: projectClone.start", + ); + const error = squashAtomCommandFailure({ cause: Cause.die(defect) }); + + expect(thrownErrorMessage(error)).toBe( + "RPC contract is registered but unavailable in the control plane: projectClone.start", + ); + }); +}); diff --git a/packages/client-runtime/src/state/runtime.ts b/packages/client-runtime/src/state/runtime.ts index f91f838db78b0..b4674a07cb469 100644 --- a/packages/client-runtime/src/state/runtime.ts +++ b/packages/client-runtime/src/state/runtime.ts @@ -404,7 +404,9 @@ export function isAtomCommandInterrupted(result: AtomCommandResult; }): unknown { - return Cause.squash(result.cause); + const squashed = Cause.squash(result.cause); + // A server `Effect.die("text")` decodes over RPC as a bare string; callers read `Error`s. + return typeof squashed === "string" ? new Error(squashed) : squashed; } export async function settleAsyncResult( From 1c9ccc7127c386a50644535070ffc9168fbf8d74 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 09:29:00 -0800 Subject: [PATCH 006/219] fix(web): a grouped project's folder New thread starts on the viewed machine's copy (#41554) --- .../src/components/Sidebar.browser.test.tsx | 61 +++++++++++++++++++ apps/web/src/components/Sidebar.tsx | 13 +++- 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/apps/web/src/components/Sidebar.browser.test.tsx b/apps/web/src/components/Sidebar.browser.test.tsx index 1fb930f55fabc..87f43d9f901f6 100644 --- a/apps/web/src/components/Sidebar.browser.test.tsx +++ b/apps/web/src/components/Sidebar.browser.test.tsx @@ -25,6 +25,7 @@ import { useNowMinute } from "../hooks/useNowMinute"; import { __setClientSettingsForTests, getClientSettings } from "../hooks/useSettings"; import { useThreadRouteTarget } from "../hooks/useThreadRouteTarget"; import { useProjects, useServerConfigs, useQuietThreadShells } from "../state/entities"; +import { useConnectedEnvironmentIds, usePrimaryEnvironmentId } from "../state/environments"; import { readEnvironmentScope, useEnvironmentScope } from "../state/session"; import { useOrchestrationCommand } from "../state/use-orchestration-command"; import { useTerminalUiStateStore } from "../terminalUiStateStore"; @@ -40,6 +41,7 @@ vi.mock(import("../state/olderSettledShelf"), async (original) => { return { ...actual, useOlderSettledShelf: vi.fn(actual.useOlderSettledShelf) }; }); vi.mock("../state/entities", { spy: true }); +vi.mock("../state/environments", { spy: true }); vi.mock("../hooks/useHandleNewThread", { spy: true }); vi.mock("../hooks/useNowMinute", { spy: true }); vi.mock("../hooks/useThreadRouteTarget", { spy: true }); @@ -132,6 +134,65 @@ describe("sidebar header new thread", () => { }); }); +// regression: #41549 a grouped project's folder New thread went to the primary copy +describe("sidebar project folder new thread", () => { + it("starts in the copy of the viewed thread, as the new-thread shortcut does", async () => { + using stack = new DisposableStack(); + const previousSettings = getClientSettings(); + stack.defer(() => __setClientSettingsForTests(previousSettings)); + __setClientSettingsForTests({ ...DEFAULT_CLIENT_SETTINGS, boringSidebarEnabled: true }); + const primary = EnvironmentId.make("local"); + const dev1 = EnvironmentId.make("dev1"); + const repositoryIdentity = { + canonicalKey: "github.com/acme/demo-repo", + locator: { + source: "git-remote" as const, + remoteName: "origin", + remoteUrl: "https://github.com/acme/demo-repo.git", + }, + displayName: "acme/demo-repo", + }; + const primaryCopy = { ...project("demo-primary"), repositoryIdentity }; + const dev1Copy = { + ...project("demo-dev1"), + environmentId: dev1, + repositoryIdentity, + }; + vi.mocked(usePrimaryEnvironmentId).mockReturnValue(primary); + vi.mocked(useConnectedEnvironmentIds).mockReturnValue([primary, dev1]); + vi.mocked(useProjects).mockReturnValue([primaryCopy, dev1Copy]); + const dev1Thread = makeThreadFixture({ + environmentId: dev1, + id: ThreadId.make("dev1-thread"), + projectId: dev1Copy.id, + title: "dev1 work", + }); + vi.mocked(useQuietThreadShells).mockReturnValue([dev1Thread]); + const threadRef = scopeThreadRef(dev1, dev1Thread.id); + vi.mocked(useThreadRouteTarget).mockReturnValue({ kind: "server", threadRef }); + const dev1ProjectRef = scopeProjectRef(dev1, dev1Copy.id); + const startThread = vi.fn().mockResolvedValue(null); + vi.mocked(useHandleNewThread).mockReturnValue({ + activeDraftThread: null, + activeThread: dev1Thread, + defaultProjectRef: dev1ProjectRef, + defaultProjectFallbackReady: true, + handleNewThread: startThread, + routeDraftId: null, + routeThreadRef: threadRef, + }); + + await using screen = await render( + + + , + ); + await userEvent.click(screen.getByRole("button", { name: "New thread in acme/demo-repo" })); + + expect(startThread).toHaveBeenCalledExactlyOnceWith(dev1ProjectRef); + }); +}); + // regression: #38623 unsent drafts are listed above threads but mod+1..9 skipped them describe("sidebar numbered jumps", () => { it("numbers the unsent draft at the top before the threads below it", async () => { diff --git a/apps/web/src/components/Sidebar.tsx b/apps/web/src/components/Sidebar.tsx index 9c1918be6b8e7..59fcb56bfce9d 100644 --- a/apps/web/src/components/Sidebar.tsx +++ b/apps/web/src/components/Sidebar.tsx @@ -114,6 +114,7 @@ import { selectProjectGroupingSettings, } from "@t3tools/client-runtime/state/project-grouping"; import { + buildSidebarProjectPickerEntries, projectGroupsSpanEnvironments, resolveSidebarProjectScopeKeys, getSidebarProjectSettingsKey, @@ -135,7 +136,7 @@ import { useProjectPin } from "../hooks/useProjectGroupUpdate"; import { useSidebarProjectGroups } from "../hooks/useSidebarProjectGroups"; import { isCommandPaletteOpen, openCommandPalette } from "../commandPaletteBus"; import { registerSettleAndAdvance } from "../settleAndAdvance"; -import { startNewThreadFromContext } from "../lib/chatThreadActions"; +import { resolveThreadActionProjectRef, startNewThreadFromContext } from "../lib/chatThreadActions"; import { useClientSettings } from "../hooks/useSettings"; import { useCopyToClipboard } from "../hooks/useCopyToClipboard"; import { useLocalStorage } from "../hooks/useLocalStorage"; @@ -1267,7 +1268,15 @@ export default function Sidebar({ routeReveal }: { routeReveal: SidebarRouteReve ); const startThreadInProjectFolder = useStableCallback((group: SidebarProjectSnapshot) => { if (isMobile) setOpenMobile(false); - void handleNewThread(scopeProjectRef(group.environmentId, group.id)); + const [entry] = buildSidebarProjectPickerEntries({ + groups: [group], + preferredProjectRef: resolveThreadActionProjectRef({ + ...newThreadContext, + activeThread: newThreadContext.activeThread ?? undefined, + }), + }); + const target = entry?.targetProject ?? group; + void handleNewThread(scopeProjectRef(target.environmentId, target.id)); }); const handleProjectFolderContextMenu = useStableCallback( ( From a9bec417292b06e3c180bb0ee6b1eb9e70d47986 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 23 Nov 2026 11:31:28 -0600 Subject: [PATCH 007/219] fix(web): Office previews open files with malformed external links or spaced sheet names (#41547) Co-authored-by: Julius Marminge --- .../components/files/officeArchive.test.ts | 85 ++++++++++++++++++- .../web/src/components/files/officeArchive.ts | 26 +++--- 2 files changed, 100 insertions(+), 11 deletions(-) diff --git a/apps/web/src/components/files/officeArchive.test.ts b/apps/web/src/components/files/officeArchive.test.ts index 7e50bf5c80b02..fd8718e21fdcf 100644 --- a/apps/web/src/components/files/officeArchive.test.ts +++ b/apps/web/src/components/files/officeArchive.test.ts @@ -15,6 +15,7 @@ async function wordFile( body: string, parts: Partial> = {}, section = "", + extraRels = "", ) { const zip = new JSZip(); zip.file( @@ -31,7 +32,7 @@ async function wordFile( parts, ) .map((part) => relationship(part, `${part}.xml`)) - .join("")}`, + .join("")}${extraRels}`, ); for (const [part, xml] of Object.entries(parts)) zip.file(`word/${part}.xml`, xml); zip.file( @@ -148,4 +149,86 @@ describe("Word preview limits", () => { expect(await result.part("word/footnotes.xml")).toBe(footnotes); expect(await result.part("word/document.xml")).toContain("Body"); }); + + it("drops a malformed external hyperlink relationship while keeping body text", async () => { + const result = await prepared( + await wordFile( + paragraph("Body text"), + {}, + "", + ``, + ), + ); + expect(result.truncated).toBe(false); + expect(await result.part("word/document.xml")).toContain("Body text"); + expect(await result.part("word/_rels/document.xml.rels")).not.toContain("badLink"); + }); +}); + +async function workbookFile( + target: string, + sheetPath: string, + extraRels = "", + targetMode = "Internal", +) { + const zip = new JSZip(); + zip.file( + "[Content_Types].xml", + ``, + ); + zip.file( + "_rels/.rels", + `${relationship("officeDocument", "xl/workbook.xml")}`, + ); + zip.file( + "xl/workbook.xml", + ``, + ); + zip.file( + "xl/_rels/workbook.xml.rels", + `${extraRels}`, + ); + zip.file( + sheetPath, + `42`, + ); + return zip.generateAsync({ type: "arraybuffer" }); +} + +describe("Workbook relationship targets", () => { + it.each(["sheet 1.xml", "sheet%201.xml", "sheet#1.xml"])( + "prepares a worksheet whose ZIP name matches its target literally (%s)", + async (name) => { + const result = await prepareOffice( + await workbookFile(`worksheets/${name}`, `xl/worksheets/${name}`), + "xlsx", + ); + const zip = await JSZip.loadAsync(result.bytes); + expect(result.truncated).toBe(false); + expect(await zip.file(`xl/worksheets/${name}`)?.async("string")).toContain("42"); + }, + ); + + it("refuses a worksheet whose relationship is external", async () => { + await expect( + prepareOffice( + await workbookFile("worksheets/sheet2.xml", "xl/worksheets/sheet2.xml", "", "External"), + "xlsx", + ), + ).rejects.toMatchObject({ code: "workbook-sheet-count" }); + }); + + it("handles a malformed external relationship in workbook relationships", async () => { + const result = await prepareOffice( + await workbookFile( + "worksheets/sheet1.xml", + "xl/worksheets/sheet1.xml", + ``, + ), + "xlsx", + ); + const zip = await JSZip.loadAsync(result.bytes); + expect(result.truncated).toBe(false); + expect(await zip.file("xl/worksheets/sheet1.xml")?.async("string")).toContain("42"); + }); }); diff --git a/apps/web/src/components/files/officeArchive.ts b/apps/web/src/components/files/officeArchive.ts index aabfc0b21f6dc..0e9b59ab8e9eb 100644 --- a/apps/web/src/components/files/officeArchive.ts +++ b/apps/web/src/components/files/officeArchive.ts @@ -598,10 +598,16 @@ async function boundWorkbook(archive: JSZip) { relationships.on("opentag", (tag) => { if (tag.local !== "Relationship") return; const type = tag.attributes.Type?.value; - const path = new URL( - tag.attributes.Target?.value ?? "", - "https://docx.invalid/xl/workbook.xml", - ).pathname.slice(1); + const target = tag.attributes.Target?.value ?? ""; + // Resolve as the engine does: literal ZIP names split on `/`, never URL syntax or escapes. + const segments = target.startsWith("/") ? [] : ["xl"]; + for (const segment of target.split("/")) { + if (segment === "..") segments.pop(); + else if (segment && segment !== ".") segments.push(segment); + } + const external = tag.attributes.TargetMode?.value.toLowerCase() === "external"; + // The engine reads an external worksheet from its default part, so leave it unresolved to refuse it. + const path = external && type?.endsWith("/worksheet") ? "" : segments.join("/"); if (type?.endsWith("/worksheet")) paths.set(tag.attributes.Id?.value ?? "", path); else if (/\/(?:chartsheet|dialogsheet|xlMacrosheet|xlIntlMacrosheet)$/.test(type ?? "")) otherSheets.add(tag.attributes.Id?.value ?? ""); @@ -755,13 +761,13 @@ function wordPartTypes() { const external = attr("TargetMode").toLowerCase() === "external" || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(attr("Target")); - const folder = path === "_rels/.rels" ? "" : path.replace(/_rels\/[^/]+\.rels$/, ""); - // Preserve archive URL resolution, including literal query/fragment - // characters in ZIP names rather than silently classifying another file. - const target = new URL(attr("Target"), `https://docx.invalid/${folder}`) - .toString() - .slice("https://docx.invalid/".length); if (!external) { + const folder = path === "_rels/.rels" ? "" : path.replace(/_rels\/[^/]+\.rels$/, ""); + // Preserve archive URL resolution, including literal query/fragment + // characters in ZIP names rather than silently classifying another file. + const target = new URL(attr("Target"), `https://docx.invalid/${folder}`) + .toString() + .slice("https://docx.invalid/".length); if ( !WORD_BINARY_PARTS.has(role) && role !== "hyperlink" && From fa2ee196b5b4d371aecdedbebc3cdbc0c20c8553 Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 09:35:37 -0800 Subject: [PATCH 008/219] fix(web): archived threads settings stay responsive with thousands of threads (#41539) --- .../settings/ArchivedThreadsPanel.tsx | 175 ++++++++++++------ 1 file changed, 118 insertions(+), 57 deletions(-) diff --git a/apps/web/src/components/settings/ArchivedThreadsPanel.tsx b/apps/web/src/components/settings/ArchivedThreadsPanel.tsx index c44d37a359b1b..0ea512be7f9d5 100644 --- a/apps/web/src/components/settings/ArchivedThreadsPanel.tsx +++ b/apps/web/src/components/settings/ArchivedThreadsPanel.tsx @@ -23,7 +23,8 @@ import { useSearchableSetting } from "./settingsSearch"; import { ProjectFavicon } from "../ProjectFavicon"; import { msg, T, useGT, useMessages } from "gt-react"; -import { useRef, useState } from "react"; +import { type ReactNode, useRef, useState } from "react"; +import { observeIntersection } from "~/lib/observeIntersection"; import { Tooltip, TooltipTrigger, TooltipPopup } from "../ui/tooltip"; const ARCHIVE_ACTIONS = [ @@ -44,6 +45,43 @@ const ARCHIVE_ACTIONS = [ ] as const; type ArchiveAction = (typeof ARCHIVE_ACTIONS)[number]["action"]; +const ARCHIVED_ROW_CHUNK_SIZE = 50; +const ESTIMATED_ARCHIVED_ROW_PX = 67; + +// Thousands of archived threads would mount at once, so each chunk of rows mounts only near the +// visible part of the settings scroller and otherwise keeps its last measured height. +function ArchivedThreadChunk(props: { + readonly rowCount: number; + readonly initiallyMounted: boolean; + readonly renderRows: () => ReactNode; +}) { + const { rowCount } = props; + const [view, setView] = useState({ + near: props.initiallyMounted, + rowHeight: ESTIMATED_ARCHIVED_ROW_PX, + }); + return ( +
{ + if (!node) return; + return observeIntersection( + node, + (entry) => + setView({ + near: entry.isIntersecting, + rowHeight: entry.boundingClientRect.height / rowCount, + }), + { root: node.closest("[data-settings-page-scroll]"), rootMargin: "1200px 0px" }, + ); + }} + className="*:not-first:border-t *:not-first:border-border/50" + style={view.near ? undefined : { height: view.rowHeight * rowCount }} + > + {view.near ? props.renderRows() : null} +
+ ); +} + export function ArchivedThreadsPanel() { const searchableSetting = useSearchableSetting(); const gt = useGT(); @@ -139,15 +177,21 @@ export function ArchivedThreadsPanel() { } } } - const sortedGroups = Array.from(groups, ([key, group]) => ({ - ...group, - key, - threads: group.threads.toSorted((left, right) => { - const leftKey = left.archivedAt ?? left.createdAt; - const rightKey = right.archivedAt ?? right.createdAt; - return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id); - }), - })); + const sortedGroups = []; + let firstRow = 0; + for (const [key, group] of groups) { + sortedGroups.push({ + ...group, + key, + firstRow, + threads: group.threads.toSorted((left, right) => { + const leftKey = left.archivedAt ?? left.createdAt; + const rightKey = right.archivedAt ?? right.createdAt; + return rightKey.localeCompare(leftKey) || right.id.localeCompare(left.id); + }), + }); + firstRow += group.threads.length; + } return { groups: sortedGroups, hasMultipleEnvironments }; })(); @@ -210,6 +254,54 @@ export function ArchivedThreadsPanel() { reportFailure(result, gt("Archived thread action failed")); }; + const renderRow = (thread: ArchivedThread) => { + const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)); + return ( + { + event.preventDefault(); + void handleContextMenu(thread, { x: event.clientX, y: event.clientY }); + }} + title={thread.title} + description={ + + {hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null} + + Archived + {" \u00b7 Created "} + + + + } + control={ +
+ {ARCHIVE_ACTIONS.map(({ action, label, threadLabel, Icon }) => ( + + void handleThreadAction(action, thread)} + /> + } + > + + + {m(label)} + + ))} +
+ } + /> + ); + }; + return ( {archivedGroups.length === 0 ? ( @@ -240,59 +332,28 @@ export function ArchivedThreadsPanel() { /> ) : ( - archivedGroups.map(({ key, project, title, threads: projectThreads }, index) => ( + archivedGroups.map(({ key, project, title, firstRow, threads: projectThreads }, index) => ( } > - {projectThreads.map((thread) => { - const threadKey = scopedThreadKey(scopeThreadRef(thread.environmentId, thread.id)); - return ( - { - event.preventDefault(); - void handleContextMenu(thread, { x: event.clientX, y: event.clientY }); - }} - title={thread.title} - description={ - - {hasMultipleEnvironments ? `${thread.environmentLabel} · ` : null} - - Archived - {" \u00b7 Created "} - - - - } - control={ -
- {ARCHIVE_ACTIONS.map(({ action, label, threadLabel, Icon }) => ( - - void handleThreadAction(action, thread)} - /> - } - > - - - {m(label)} - - ))} -
- } - /> - ); - })} + {Array.from( + { length: Math.ceil(projectThreads.length / ARCHIVED_ROW_CHUNK_SIZE) }, + (_, chunkIndex) => { + const start = chunkIndex * ARCHIVED_ROW_CHUNK_SIZE; + const rows = projectThreads.slice(start, start + ARCHIVED_ROW_CHUNK_SIZE); + return ( + rows.map(renderRow)} + /> + ); + }, + )}
)) )} From 6aad800ecfe268c158af60d1102c3ec4acc9bab9 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 23 Nov 2026 11:53:50 -0600 Subject: [PATCH 009/219] fix(server): EPUB chapters with a query in their href extract their text (#41553) Co-authored-by: Julius Marminge --- apps/server/src/provider/documentTextWorker.ts | 2 +- apps/server/src/provider/userInputAttachments.test.ts | 11 +++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/apps/server/src/provider/documentTextWorker.ts b/apps/server/src/provider/documentTextWorker.ts index 027029139a77e..3fe14f40ddbf6 100644 --- a/apps/server/src/provider/documentTextWorker.ts +++ b/apps/server/src/provider/documentTextWorker.ts @@ -864,7 +864,7 @@ async function* document(path: string, extension: string): AsyncGenerator { ], absent: ["[Extracted text truncated"], }, + { + ext: "epub", + parts: { + "META-INF/container.xml": '', + "book.opf": + '', + "q?1.xhtml": "

Encoded question mark chapter text.

", + }, + expected: ["Encoded question mark chapter text."], + absent: ["[Skipped document part", "[Extracted text truncated"], + }, { ext: "epub", parts: { From 0ea0db39e272a472f26b97e9bfc3a6c7805112f2 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 23 Nov 2026 12:01:33 -0600 Subject: [PATCH 010/219] fix(shared): PascalCase test doubles like MockTransport.ts count as mocks (#41561) Co-authored-by: Julius Marminge --- packages/shared/src/changedFileKind.test.ts | 5 +++++ packages/shared/src/changedFileKind.ts | 7 ++++--- 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/packages/shared/src/changedFileKind.test.ts b/packages/shared/src/changedFileKind.test.ts index f16ad777d895c..f77db79426740 100644 --- a/packages/shared/src/changedFileKind.test.ts +++ b/packages/shared/src/changedFileKind.test.ts @@ -6,6 +6,11 @@ describe("classifyChangedFile", () => { it.each([ ["src/contest.py", "code"], ["test/fixtures/pr.json", "mocks"], + ["src/MockTransport.ts", "mocks"], + ["src/FakeClock.ts", "mocks"], + ["src/Foo.Mock.ts", "mocks"], + ["src/Mockup.ts", "code"], + ["src/Stubborn.ts", "code"], ["pnpm-lock.yaml", "generated"], ["convex/_generated/api.d.ts", "generated"], ["src/agent.eval.ts", "tests"], diff --git a/packages/shared/src/changedFileKind.ts b/packages/shared/src/changedFileKind.ts index 7da5ba5cb0c11..dca226bd06fc8 100644 --- a/packages/shared/src/changedFileKind.ts +++ b/packages/shared/src/changedFileKind.ts @@ -47,8 +47,9 @@ const GENERATED_NAME = /(\.generated\.|\.gen\.|\.g\.dart$|\.pb\.go$|_pb2(_grpc)?\.py$|\.pb\.(cc|h)$|\.min\.(js|css)$|\.(js|css)\.map$)/; const GENERATED_DIRS = new Set(["__generated__", "_generated", "generated"]); -const MOCK_NAME = - /(\.snap$|\.(mocks?|fixtures?|stubs?|fakes?)\.[^.]+$|^(mocks?|fixtures?|stubs?|fakes?)([-_.A-Z]|$))/; +const MOCK_NAME = /(\.snap$|\.(mocks?|fixtures?|stubs?|fakes?)\.[^.]+$)/i; +// Case-sensitive after the prefix: `MockClock.ts` is a mock, `Mockup.ts` is not. +const MOCK_PREFIX = /^([Mm]ocks?|[Ff]ixtures?|[Ss]tubs?|[Ff]akes?)([-_.A-Z]|$)/; const MOCK_DIRS = new Set([ "__fixtures__", "__mocks__", @@ -99,7 +100,7 @@ export function classifyChangedFile(path: string): ChangedFileKind { const inDir = (set: ReadonlySet) => dirs.some((dir) => set.has(dir)); if (GENERATED_FILES.has(name.toLowerCase()) || GENERATED_NAME.test(name) || inDir(GENERATED_DIRS)) return "generated"; - if (MOCK_NAME.test(name) || inDir(MOCK_DIRS)) return "mocks"; + if (MOCK_NAME.test(name) || MOCK_PREFIX.test(name) || inDir(MOCK_DIRS)) return "mocks"; if (TEST_NAME.test(name) || CLASS_TEST_NAME.test(name) || inDir(TEST_DIRS)) return "tests"; if (DOCS_NAME.test(name) && !NOT_DOCS_NAME.test(name)) return "docs"; return "code"; From 7f0e736cdba5987e2bc9a9e82e03cfde2d80b62a Mon Sep 17 00:00:00 2001 From: Julius Marminge Date: Mon, 23 Nov 2026 10:21:19 -0800 Subject: [PATCH 011/219] fix(server): GitHub issue URLs with no project on their host name the missing project (#41581) --- apps/server/src/issue/IssueService.test.ts | 21 +++++++++++++++++++++ apps/server/src/issue/IssueService.ts | 5 ++++- 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/apps/server/src/issue/IssueService.test.ts b/apps/server/src/issue/IssueService.test.ts index 26d02c06bfe66..f658c26f6c63c 100644 --- a/apps/server/src/issue/IssueService.test.ts +++ b/apps/server/src/issue/IssueService.test.ts @@ -349,6 +349,27 @@ describe("IssueService", () => { }), ); + it.effect( + "does not call a GitHub issue URL unbrowsable when no project is a GitHub checkout", + () => + Effect.gen(function* () { + // A plain folder project, while GitHub itself is a supported tracker. + const service = yield* makeService({ + projects: [project({ id: "folder" })], + trackers: [fakeTracker()], + }); + const resolved = yield* service + .resolveUrl("https://github.com/acme/web/issues/1", "folder" as ProjectId) + .pipe(Effect.result); + if (resolved._tag === "Failure") { + expect(resolved.failure).not.toMatchObject({ + _tag: "IssueUnavailableError", + reason: "tracker-unsupported", + }); + } + }), + ); + it.effect("resolves both legacy Azure work item URLs through the bound project", () => Effect.gen(function* () { const tracker = IssueTrackerKind.make("azure-devops"); diff --git a/apps/server/src/issue/IssueService.ts b/apps/server/src/issue/IssueService.ts index 01d8b47382eef..1a913c9b0725f 100644 --- a/apps/server/src/issue/IssueService.ts +++ b/apps/server/src/issue/IssueService.ts @@ -824,7 +824,10 @@ const make = Effect.gen(function* () { if (standalone === null) { const found = serve(onTracker); if (found === null) { - return yield* new IssueUnavailableError({ reason: "tracker-unsupported" }); + return yield* new IssueOperationError({ + operation: "resolveUrl", + detail: `No project in T3 Code is on ${link.host}. Add any ${link.host} project to read its issues.`, + }); } return found.resolved; } From a369642c1c5c7a9a1e6b906167e3309005ad23e4 Mon Sep 17 00:00:00 2001 From: Victor Date: Mon, 23 Nov 2026 12:32:01 -0600 Subject: [PATCH 012/219] fix(web): keys pressed on a focused video stay with the player (#41578) Co-authored-by: Julius Marminge --- .../components/chat/composerFocusRedirect.ts | 1 + .../chat/useChatShortcuts.browser.test.tsx | 18 ++++++++++++++++++ 2 files changed, 19 insertions(+) diff --git a/apps/web/src/components/chat/composerFocusRedirect.ts b/apps/web/src/components/chat/composerFocusRedirect.ts index cb187e73ea6a7..2fc544a31c9b4 100644 --- a/apps/web/src/components/chat/composerFocusRedirect.ts +++ b/apps/web/src/components/chat/composerFocusRedirect.ts @@ -12,6 +12,7 @@ const TYPE_TO_FOCUS_INTERACTIVE_SELECTOR = [ "button", "a[href]", "summary", + "video[controls]", '[role="application"]', '[role="button"]', '[role="checkbox"]', diff --git a/apps/web/src/components/chat/useChatShortcuts.browser.test.tsx b/apps/web/src/components/chat/useChatShortcuts.browser.test.tsx index 61127d1a9d9c8..378bc2b5cce74 100644 --- a/apps/web/src/components/chat/useChatShortcuts.browser.test.tsx +++ b/apps/web/src/components/chat/useChatShortcuts.browser.test.tsx @@ -245,3 +245,21 @@ it("runs right panel commands from inside a side chat pane, but not thread comma expect(ran).toEqual(["toggle", "close", "toggle"]); }); + +it("leaves keys to a focused video player with controls", async () => { + const composerKeys: string[] = []; + await using _screen = await render( + <> + +