@devries-cameron20 / t3code Mirror · read-only / commits / 27805ef76e
Fork 0

The best way to control Claude Code, Codex and more from any computer or phone

Mirrored from https://github.com/Camo67/t3code.git

Synced Nov 22, 18:15 UTC

fix(web): preview images outside the workspace (#24627)

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>

Julius Marminge committed Oct 24, 2026 at 17:36 UTC 27805ef76e4f852fa86be4f93df142dabc71c32a
3 files changed +29 -4
apps/web/src/components/files/FilePreviewPanel.test.ts
+15
@@ -110,11 +110,26 @@ describe("workspaceAssetResource", () => {
110 absolutePath: "/repo/docs/index.html",
111 };
112
113 + // regression: #21067 images outside the workspace load through the host media resource
114 + it("serves a file outside the workspace as host media and keeps workspace files on workspace access", () => {
115 + expect(
116 + workspaceAssetResource({ ...input, absolutePath: "/tmp/screenshots/shot.png", draft: false }),
117 + ).toEqual({ _tag: "media-file", threadId: "thread-1", path: "/tmp/screenshots/shot.png" });
118 + expect(workspaceAssetResource({ ...input, draft: false })).toEqual({
119 + _tag: "workspace-file",
120 + threadId: "thread-1",
121 + path: "/repo/docs/index.html",
122 + });
123 + });
124 +
125 it("names the workspace root for a draft, which the server cannot resolve from a thread", () => {
126 expect(workspaceAssetResource({ ...input, draft: true })).toEqual({
127 _tag: "draft-workspace-file",
128 cwd: "/repo",
129 path: "/repo/docs/index.html",
130 });
131 + expect(
132 + workspaceAssetResource({ ...input, absolutePath: "/tmp/screenshots/shot.png", draft: true }),
133 + ).toEqual({ _tag: "draft-workspace-file", cwd: "/repo", path: "/tmp/screenshots/shot.png" });
134 });
135 });
apps/web/src/components/files/FilePreviewPanel.tsx
+1 -3
@@ -225,10 +225,8 @@ function WorkspaceBrowserPreview(props: {
225 readonly title: string;
226 readonly workspaceMutationId: string | null;
227 }) {
228 - const insideWorkspace =
229 - mediaFileReference(props.absolutePath, props.workspaceRoot).relativePath !== undefined;
228 const resource = workspaceAssetResource({
231 - kind: insideWorkspace ? "workspace-file" : "media-file",
229 + kind: "workspace-file",
230 threadRef: props.threadRef,
231 draft: props.draft,
232 workspaceRoot: props.workspaceRoot,
apps/web/src/components/files/filePreviewMode.ts
+13 -1
@@ -1,4 +1,5 @@
1 import type { AssetResource, ProjectReadFileError, ScopedThreadRef } from "@t3tools/contracts";
2 +import { mediaFileReference } from "@t3tools/client-runtime/media-reference";
3 import { isHostPath, workspaceRelativeFilePath } from "@t3tools/shared/path";
4
5 export function resolveFilePreviewPath(path: string | null, cwd: string): string | null {
@@ -55,6 +56,11 @@ export function setMarkdownTaskChecked(
56 return `${markdown.slice(0, markerOffset + 1)}${checked ? "x" : " "}${markdown.slice(markerOffset + 2)}`;
57 }
58
59 +/**
60 + * The server only signs `workspace-file` assets below the workspace root, so a
61 + * file opened from outside it, such as an absolute link in the thread, goes
62 + * through the host `media-file` resource the direct media viewer uses.
63 + */
64 export function workspaceAssetResource(input: {
65 readonly kind: "workspace-file" | "media-file";
66 readonly threadRef: ScopedThreadRef;
@@ -65,5 +71,11 @@ export function workspaceAssetResource(input: {
71 if (input.draft) {
72 return { _tag: "draft-workspace-file", cwd: input.workspaceRoot, path: input.absolutePath };
73 }
68 - return { _tag: input.kind, threadId: input.threadRef.threadId, path: input.absolutePath };
74 + const insideWorkspace =
75 + mediaFileReference(input.absolutePath, input.workspaceRoot).relativePath !== undefined;
76 + return {
77 + _tag: insideWorkspace ? input.kind : "media-file",
78 + threadId: input.threadRef.threadId,
79 + path: input.absolutePath,
80 + };
81 }