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 21, 19:45 UTC
fix(client-runtime): relative Markdown images in a remote thread no longer show the desktop's file (#35031)
Julius Marminge committed
Nov 12, 2026 at 03:00 UTC
3a815e9749484ec52418a363fced5776e5b2c691
8 files changed
+116
-4
apps/web/src/components/ChatMarkdown.tsx
+1
@@ -1624,6 +1624,7 @@ const CHAT_MARKDOWN_COMPONENTS = {
1624
_tag: "media-file",
1625
threadId: threadRef.threadId,
1626
path: imageSource.path,
1627
+ ...(imageSource.relative ? { hostOnly: true as const } : {}),
1628
}}
1629
alt={altText}
1630
kind={kind}
packages/client-runtime/src/markdownImages.test.ts
+1
@@ -16,6 +16,7 @@ describe("classifyMarkdownImageSource", () => {
16
expect(classifyMarkdownImageSource(source, workspaceRoot)).toEqual({
17
_tag: "WorkspaceFile",
18
path,
19
+ ...(source.startsWith("file:") ? {} : { relative: true }),
20
});
21
});
22
packages/client-runtime/src/markdownImages.ts
+2
-2
@@ -15,7 +15,7 @@ const URI_SCHEME_PATTERN = /^[A-Za-z][A-Za-z0-9+.-]*:/;
15
16
export type MarkdownImageSource =
17
| { readonly _tag: "Direct"; readonly uri: string }
18
- | { readonly _tag: "WorkspaceFile"; readonly path: string }
18
+ | { readonly _tag: "WorkspaceFile"; readonly path: string; readonly relative?: true }
19
| { readonly _tag: "Blocked" };
20
21
export function markdownImageSourceFragment(source: string): string {
@@ -69,5 +69,5 @@ export function classifyMarkdownImageSource(
69
}
70
if (!workspaceRoot) return { _tag: "Blocked" };
71
72
- return { _tag: "WorkspaceFile", path: joinWorkspacePath(workspaceRoot, path) };
72
+ return { _tag: "WorkspaceFile", path: joinWorkspacePath(workspaceRoot, path), relative: true };
73
}
packages/client-runtime/src/mediaSource.test.ts
+1
-1
@@ -83,7 +83,7 @@ describe("resolveMediaSource", () => {
83
},
84
srcFragment: "#mark",
85
access: "environment",
86
- resource: { _tag: "media-file", threadId, path: "/repo/screens/logo.svg" },
86
+ resource: { _tag: "media-file", threadId, path: "/repo/screens/logo.svg", hostOnly: true },
87
});
88
});
89
packages/client-runtime/src/mediaSource.ts
+6
-1
@@ -101,6 +101,11 @@ export function resolveMediaSource(
101
return {
102
...common,
103
access: "environment",
104
- resource: { _tag: "media-file", threadId: input.threadId, path },
104
+ resource: {
105
+ _tag: "media-file",
106
+ threadId: input.threadId,
107
+ path,
108
+ ...(classified.relative ? { hostOnly: true as const } : {}),
109
+ },
110
};
111
}
packages/client-runtime/src/state/assets.test.ts
+102
@@ -2,6 +2,7 @@ import { describe, expect, it } from "@effect/vitest";
2
import {
3
type AssetCreateUrlResult,
4
type AssetResource,
5
+ AssetWorkspaceAssetNotFoundError,
6
EnvironmentId,
7
ThreadId,
8
WS_METHODS,
@@ -23,6 +24,7 @@ import {
24
} from "../connection/model.ts";
25
import * as EnvironmentRegistry from "../connection/registry.ts";
26
import * as EnvironmentSupervisor from "../connection/supervisor.ts";
27
+import { resolveMediaSource } from "../mediaSource.ts";
28
import type * as RpcSession from "../rpc/session.ts";
29
import {
30
ASSET_URL_MAX_IN_FLIGHT,
@@ -237,6 +239,106 @@ describe("asset URL requests", () => {
239
);
240
});
241
242
+describe("desktop-local media fallback", () => {
243
+ const remote = EnvironmentId.make("media-remote");
244
+ const local = EnvironmentId.make("media-local");
245
+ const threadId = ThreadId.make("remote-thread");
246
+
247
+ // The remote is missing every file; the desktop has one at every absolute path.
248
+ const makeFallback = Effect.fn("TestAssetUrl.makeFallback")(function* () {
249
+ const calls: Array<EnvironmentId> = [];
250
+ const supervisor = (environmentId: EnvironmentId) =>
251
+ Effect.gen(function* () {
252
+ const session = {
253
+ client: {
254
+ [WS_METHODS.assetsCreateUrl]: ({ resource }: { resource: AssetResource }) =>
255
+ Effect.suspend(() => {
256
+ calls.push(environmentId);
257
+ return environmentId === remote
258
+ ? Effect.fail(new AssetWorkspaceAssetNotFoundError({ resource }))
259
+ : Effect.succeed({ relativeUrl: "/api/assets/t/local.png", expiresAt: 4e12 });
260
+ }),
261
+ },
262
+ } as unknown as RpcSession.RpcSession;
263
+ return EnvironmentSupervisor.EnvironmentSupervisor.of({
264
+ target: new PrimaryConnectionTarget({
265
+ environmentId,
266
+ label: environmentId,
267
+ httpBaseUrl: `https://${environmentId}.test`,
268
+ wsBaseUrl: `wss://${environmentId}.test`,
269
+ }),
270
+ state: yield* SubscriptionRef.make<SupervisorConnectionState>({
271
+ ...AVAILABLE_CONNECTION_STATE,
272
+ desired: true,
273
+ network: "online",
274
+ phase: "connected",
275
+ attempt: 1,
276
+ generation: 1,
277
+ }),
278
+ session: yield* SubscriptionRef.make(Option.some(session)),
279
+ prepared: yield* SubscriptionRef.make<Option.Option<PreparedConnection>>(Option.none()),
280
+ connect: Effect.void,
281
+ disconnect: Effect.void,
282
+ retryNow: Effect.void,
283
+ } satisfies EnvironmentSupervisor.EnvironmentSupervisor["Service"]);
284
+ });
285
+ const supervisors = new Map([
286
+ [remote, yield* supervisor(remote)],
287
+ [local, yield* supervisor(local)],
288
+ ]);
289
+ type Registry = EnvironmentRegistry.EnvironmentRegistry["Service"];
290
+ const run: Registry["run"] = (environmentId, effect) =>
291
+ Effect.provideService(
292
+ effect,
293
+ EnvironmentSupervisor.EnvironmentSupervisor,
294
+ supervisors.get(environmentId)!,
295
+ );
296
+ const followStream: Registry["followStream"] = (environmentId, stream) =>
297
+ Stream.provideService(
298
+ stream,
299
+ EnvironmentSupervisor.EnvironmentSupervisor,
300
+ supervisors.get(environmentId)!,
301
+ );
302
+ const environmentRegistry = EnvironmentRegistry.EnvironmentRegistry.of({
303
+ run,
304
+ followStream,
305
+ } as unknown as Registry);
306
+ const registry = AtomRegistry.make();
307
+ yield* Effect.addFinalizer(() => Effect.sync(() => registry.dispose()));
308
+ const atoms = createAssetEnvironmentAtoms(
309
+ Atom.runtime(Layer.succeed(EnvironmentRegistry.EnvironmentRegistry, environmentRegistry)),
310
+ Atom.make({ environmentId: local, httpBaseUrl: "https://media-local.test" }),
311
+ );
312
+ const load = (source: string) => {
313
+ const media = resolveMediaSource(source, { threadId, workspaceRoot: "/tmp/repo" });
314
+ if (media?.access !== "environment") throw new Error(`${source} is not host media`);
315
+ calls.length = 0;
316
+ return AtomRegistry.getResult(
317
+ registry,
318
+ atoms.createUrl({ environmentId: remote, input: { resource: media.resource } }),
319
+ ).pipe(
320
+ Effect.result,
321
+ Effect.map((result) => ({ loaded: result._tag === "Success", calls: [...calls] })),
322
+ );
323
+ };
324
+ return { load };
325
+ });
326
+
327
+ it.effect("keeps a relative Markdown image on the thread's environment", () =>
328
+ Effect.scoped(
329
+ Effect.gen(function* () {
330
+ const { load } = yield* makeFallback();
331
+ expect(yield* load("docs/report.png")).toEqual({ loaded: false, calls: [remote] });
332
+ // The same resolved path written absolute still falls back, and shares no cached result.
333
+ expect(yield* load("/tmp/repo/docs/report.png")).toEqual({
334
+ loaded: true,
335
+ calls: [remote, local],
336
+ });
337
+ }),
338
+ ),
339
+ );
340
+});
341
+
342
const revisionedEnvironmentId = EnvironmentId.make("environment-1");
343
const revisionedResource: AssetResource = {
344
_tag: "workspace-file",
packages/client-runtime/src/state/assets.ts
+1
@@ -276,6 +276,7 @@ export function createAssetEnvironmentAtoms<R, E>(
276
error._tag === "AssetWorkspaceContextNotFoundError"
277
) ||
278
resource._tag !== "media-file" ||
279
+ resource.hostOnly ||
280
!(resource.path.startsWith("/") || isWindowsAbsolutePath(resource.path)) ||
281
mediaMimeTypeFromExtension(resource.path.slice(resource.path.lastIndexOf("."))) === null
282
)
packages/contracts/src/assets.ts
+2
@@ -34,6 +34,8 @@ export const AssetResource = Schema.Union([
34
threadId: ThreadId,
35
path: TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),
36
disposition: Schema.optionalKey(Schema.Literal("attachment")),
37
+ // Written relative to the thread's workspace, so only that host's file is meant.
38
+ hostOnly: Schema.optionalKey(Schema.Literal(true)),
39
}),
40
Schema.TaggedStruct("draft-workspace-file", {
41
cwd: TrimmedNonEmptyString.check(Schema.isMaxLength(ASSET_PATH_MAX_LENGTH)),