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, 22:00 UTC
fix: ~/ file links open in the file panel for projects outside the home folder (#20950)
Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: Julius Marminge <julius0216@outlook.com>
Ângelo Tadeucci committed
Oct 20, 2026 at 02:09 UTC
03fe16a983e8bf6bb84dce26f78c0e863f5535df
12 files changed
+98
-20
apps/server/src/assets/AssetAccess.test.ts
+30
@@ -816,6 +816,36 @@ describe("AssetAccess", () => {
816
}).pipe(Effect.provide(layerTest)),
817
);
818
819
+ it.effect("serves home-relative draft media files from the home folder", () =>
820
+ Effect.gen(function* () {
821
+ const fileSystem = yield* FileSystem.FileSystem;
822
+ const path = yield* Path.Path;
823
+ const root = yield* fileSystem.makeTempDirectoryScoped({
824
+ prefix: "t3-asset-draft-root-",
825
+ });
826
+ const home = yield* fileSystem.makeTempDirectoryScoped({
827
+ prefix: "t3-asset-draft-home-",
828
+ });
829
+ const clipPath = path.join(home, "Downloads", "clip.mp4");
830
+ yield* fileSystem.makeDirectory(path.dirname(clipPath), { recursive: true });
831
+ yield* fileSystem.writeFileString(clipPath, "video");
832
+ const canonicalClipPath = yield* fileSystem.realPath(clipPath);
833
+
834
+ const result = yield* issueAssetUrl({
835
+ resource: { _tag: "draft-workspace-file", cwd: root, path: "~/Downloads/clip.mp4" },
836
+ workspaceRoot: root,
837
+ }).pipe(Effect.provideService(HostProcess.HomeDirectory, home));
838
+ const suffix = result.relativeUrl.slice(`${ASSET_ROUTE_PREFIX}/`.length);
839
+ const token = suffix.slice(0, suffix.indexOf("/"));
840
+
841
+ expect(yield* resolveAsset(token, "clip.mp4")).toMatchObject({
842
+ kind: "file",
843
+ path: canonicalClipPath,
844
+ mimeType: "video/mp4",
845
+ });
846
+ }).pipe(Effect.provide(layerTest)),
847
+ );
848
+
849
it.effect("serves absolute draft media files exactly, wherever they live", () =>
850
Effect.gen(function* () {
851
const fileSystem = yield* FileSystem.FileSystem;
apps/server/src/assets/AssetAccess.ts
+5
-2
@@ -559,9 +559,12 @@ export const issueAssetUrl = Effect.fn("AssetAccess.issueAssetUrl")(function* (i
559
}
560
case "draft-workspace-file": {
561
const draftWorkspaceRoot = input.workspaceRoot ?? input.resource.cwd;
562
- if (path.isAbsolute(input.resource.path)) {
562
+ const hostPath = input.resource.path.startsWith("~/")
563
+ ? expandHomePath(input.resource.path, yield* HostProcess.HomeDirectory)
564
+ : input.resource.path;
565
+ if (path.isAbsolute(hostPath)) {
566
const finalized = yield* finalizeAbsoluteMediaFileAsset({
564
- requestedPath: input.resource.path,
567
+ requestedPath: hostPath,
568
resource: input.resource,
569
expiresAt,
570
});
apps/server/src/workspace/WorkspaceFileSystem.test.ts
+21
@@ -203,6 +203,27 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceFileSystemLive", (i
203
}),
204
);
205
206
+ it.effect("reads ~/ paths from the server home outside the workspace", () =>
207
+ Effect.gen(function* () {
208
+ const workspaceFileSystem = yield* WorkspaceFileSystem.WorkspaceFileSystem;
209
+ const cwd = yield* makeTempDir;
210
+ const home = yield* makeTempDir;
211
+ yield* writeTextFile(home, ".claude/CLAUDE.md", "# Notes\n");
212
+ yield* writeTextFile(cwd, "~/.claude/CLAUDE.md", "Workspace decoy\n");
213
+
214
+ const result = yield* workspaceFileSystem
215
+ .readFile({ cwd, relativePath: "~/.claude/CLAUDE.md" })
216
+ .pipe(Effect.provideService(HostProcess.HomeDirectory, home));
217
+
218
+ expect(result).toEqual({
219
+ relativePath: "~/.claude/CLAUDE.md",
220
+ contents: "# Notes\n",
221
+ byteLength: 8,
222
+ truncated: false,
223
+ });
224
+ }),
225
+ );
226
+
227
it.effect.skipIf(HostProcess.Platform.defaultValue() === "win32")(
228
"rejects a FIFO without blocking on open",
229
() =>
apps/server/src/workspace/WorkspaceFileSystem.ts
+9
-6
@@ -221,22 +221,25 @@ export const make = Effect.gen(function* () {
221
222
/**
223
* Workspace-relative paths must stay inside the root, symlinks included. An
224
- * absolute path reads a host file in place, such as a report an agent wrote to a
225
- * temp directory; it gets no root check.
224
+ * absolute or `~/` path reads a host file in place, such as a report an agent
225
+ * wrote to a temp directory; it gets no root check.
226
*/
227
const resolveReadTarget = Effect.fn("WorkspaceFileSystem.resolveReadTarget")(function* (
228
input: ProjectReadFileInput,
229
) {
230
const requestedPath = input.relativePath.trim();
231
- if (path.isAbsolute(requestedPath)) {
231
+ const hostPath = requestedPath.startsWith("~/")
232
+ ? expandHomePath(requestedPath, yield* HostProcess.HomeDirectory)
233
+ : requestedPath;
234
+ if (path.isAbsolute(hostPath)) {
235
const realTargetPath = yield* Effect.tryPromise({
233
- try: () => NodeFSP.realpath(requestedPath),
236
+ try: () => NodeFSP.realpath(hostPath),
237
catch: (cause) =>
238
new WorkspaceFileSystemOperationError({
239
workspaceRoot: input.cwd,
240
relativePath: input.relativePath,
238
- resolvedPath: requestedPath,
239
- operationPath: requestedPath,
241
+ resolvedPath: hostPath,
242
+ operationPath: hostPath,
243
operation: "realpath-target",
244
cause,
245
}),
apps/web/src/components/ChatMarkdown.tsx
+2
-2
@@ -12,7 +12,7 @@ import {
12
extractMarkdownLinkHrefs,
13
inlineCodeFilePathCandidate,
14
} from "@t3tools/shared/markdownLinks";
15
-import { isAbsolutePath, resolveWorkspaceFilePath } from "@t3tools/shared/path";
15
+import { isHostPath, resolveWorkspaceFilePath } from "@t3tools/shared/path";
16
import { usePullRequestLinking } from "~/hooks/usePullRequestLinking";
17
import { AuthFilesystemReadScope, AuthOrchestrationOperateScope } from "@t3tools/contracts";
18
import {
@@ -2752,7 +2752,7 @@ function useChatMarkdownState({
2752
) !== null;
2753
const panelPath =
2754
fileLinkMeta.workspaceRelativePath ??
2755
- (!canPreviewMedia && isAbsolutePath(fileLinkMeta.filePath) ? fileLinkMeta.filePath : null);
2755
+ (!canPreviewMedia && isHostPath(fileLinkMeta.filePath) ? fileLinkMeta.filePath : null);
2756
2757
return (
2758
<MarkdownFileLink
apps/web/src/components/files/FileBreadcrumbs.tsx
+2
-2
@@ -19,7 +19,7 @@ import { Tooltip, TooltipPopup, TooltipTrigger } from "~/components/ui/tooltip";
19
import { useTheme } from "~/hooks/useTheme";
20
import { useWorkspaceMutationRefresh } from "~/hooks/useWorkspaceMutationRefresh";
21
import { cn } from "~/lib/utils";
22
-import { isAbsolutePath } from "@t3tools/shared/path";
22
+import { isHostPath } from "@t3tools/shared/path";
23
24
import {
25
breadcrumbPathOf,
@@ -300,7 +300,7 @@ function FolderBreadcrumb(props: {
300
* menu: the browser below already lists the folder it moves to.
301
*/
302
export function FileBreadcrumbs(props: FileBreadcrumbsProps) {
303
- const hostPath = isAbsolutePath(props.relativePath);
303
+ const hostPath = isHostPath(props.relativePath);
304
const breadcrumbs = fileBreadcrumbs(props.projectName, props.trail);
305
const currentPath = breadcrumbPathOf(props.relativePath);
306
const currentIndex = breadcrumbs.findIndex((crumb) => crumb.path === currentPath);
apps/web/src/components/files/FilePreviewPanel.test.ts
+7
@@ -129,6 +129,13 @@ describe("shouldShowFileExplorer", () => {
129
attachmentOpen: false,
130
}),
131
).toBe(false);
132
+ expect(
133
+ shouldShowFileExplorer({
134
+ relativePath: "~/.claude/CLAUDE.md",
135
+ explorerOpen: true,
136
+ attachmentOpen: false,
137
+ }),
138
+ ).toBe(false);
139
expect(
140
shouldShowFileExplorer({
141
relativePath: "report.pdf",
apps/web/src/components/files/FilePreviewPanel.tsx
+2
-2
@@ -58,7 +58,7 @@ import { resolveDiffThemeName } from "~/lib/diffRendering";
58
import { PREFERRED_HIGHLIGHTER } from "~/lib/syntaxHighlighting";
59
import { cn } from "~/lib/utils";
60
import type { ChatFileAttachment } from "~/types";
61
-import { isAbsolutePath } from "@t3tools/shared/path";
61
+import { isHostPath } from "@t3tools/shared/path";
62
import { resolvePathLinkTarget } from "@t3tools/shared/fileLinks";
63
import { ScrollArea } from "~/components/ui/scroll-area";
64
import { stackedThreadToast, toastManager } from "~/components/ui/toast";
@@ -1015,7 +1015,7 @@ export default function FilePreviewPanel({
1015
const isPdf = relativePath !== null && isPdfPreviewFile(relativePath);
1016
const isHtml = relativePath !== null && !isPdf && isBrowserPreviewFile(relativePath);
1017
const isHostFile =
1018
- attachment !== undefined || (relativePath !== null && isAbsolutePath(relativePath));
1018
+ attachment !== undefined || (relativePath !== null && isHostPath(relativePath));
1019
const fileAccess = useFilesystemReadAccess(environmentId);
1020
const { canReadFiles } = fileAccess;
1021
const canWriteFiles = useEnvironmentScope(environmentId, AuthFilesystemWriteScope);
apps/web/src/components/files/filePath.test.ts
+9
@@ -47,6 +47,15 @@ describe("fileBreadcrumbs", () => {
47
"\\\\server\\share\\report.md",
48
]);
49
});
50
+
51
+ it("builds home-relative breadcrumbs with navigable child folders", () => {
52
+ expect(fileBreadcrumbs("t3code", "~/.claude/CLAUDE.md")).toEqual([
53
+ { label: "~", path: "~", kind: "directory" },
54
+ { label: ".claude", path: "~/.claude", kind: "directory" },
55
+ { label: "CLAUDE.md", path: "~/.claude/CLAUDE.md", kind: "file" },
56
+ ]);
57
+ expect(isListableHostFolder("~/.claude")).toBe(true);
58
+ });
59
});
60
61
describe("breadcrumbPathOf", () => {
apps/web/src/components/files/filePath.ts
+4
-4
@@ -1,5 +1,5 @@
1
import type { ProjectEntry } from "@t3tools/contracts";
2
-import { isWindowsAbsolutePath, isAbsolutePath } from "@t3tools/shared/path";
2
+import { isWindowsAbsolutePath, isHostPath } from "@t3tools/shared/path";
3
4
export interface FileBreadcrumb {
5
label: string;
@@ -12,10 +12,10 @@ export interface FileBreadcrumbChild extends ProjectEntry {
12
}
13
14
export function fileBreadcrumbs(projectName: string, relativePath: string): FileBreadcrumb[] {
15
- const hostPath = isAbsolutePath(relativePath);
15
+ const hostPath = isHostPath(relativePath);
16
const separator = isWindowsAbsolutePath(relativePath) ? "\\" : "/";
17
const parts = relativePath.split(/[\\/]/).filter(Boolean);
18
- const root = relativePath.startsWith("\\\\") ? "\\\\" : hostPath && separator === "/" ? "/" : "";
18
+ const root = relativePath.startsWith("\\\\") ? "\\\\" : relativePath.startsWith("/") ? "/" : "";
19
return [
20
...(hostPath ? [] : [{ label: projectName, path: "", kind: "project" as const }]),
21
...parts.map((part, index) => {
@@ -43,7 +43,7 @@ export function breadcrumbPathOf(relativePath: string): string {
43
* server (`\\server`) is not one; its shares (`\\server\share`) are.
44
*/
45
export function isListableHostFolder(path: string): boolean {
46
- return isAbsolutePath(path) && !/^\\\\[^\\/]+$/.test(path);
46
+ return isHostPath(path) && !/^\\\\[^\\/]+$/.test(path);
47
}
48
49
/** Index of `path`'s crumb among `trail`'s crumbs; -1 when the trail does not pass through it. */
apps/web/src/components/files/filePreviewMode.ts
+2
-2
@@ -1,5 +1,5 @@
1
import type { AssetResource, ProjectReadFileError, ScopedThreadRef } from "@t3tools/contracts";
2
-import { isAbsolutePath, workspaceRelativeFilePath } from "@t3tools/shared/path";
2
+import { isHostPath, workspaceRelativeFilePath } from "@t3tools/shared/path";
3
4
export function resolveFilePreviewPath(path: string | null, cwd: string): string | null {
5
if (path === null) return null;
@@ -32,7 +32,7 @@ export function shouldShowFileExplorer(input: {
32
readonly explorerOpen: boolean;
33
readonly attachmentOpen: boolean;
34
}): boolean {
35
- if (input.attachmentOpen || (input.relativePath && isAbsolutePath(input.relativePath))) {
35
+ if (input.attachmentOpen || (input.relativePath && isHostPath(input.relativePath))) {
36
return false;
37
}
38
return input.explorerOpen || input.relativePath === null;
packages/shared/src/path.ts
+5
@@ -105,6 +105,11 @@ export function isAbsolutePath(value: string): boolean {
105
return value.startsWith("/") || isWindowsAbsolutePath(value);
106
}
107
108
+/** Home-relative host paths are expanded by the destination server. */
109
+export function isHostPath(value: string): boolean {
110
+ return isAbsolutePath(value) || value.startsWith("~/");
111
+}
112
+
113
export function resolveWorkspaceFilePath(path: string, workspaceRoot: string): string {
114
if (isAbsolutePath(path) || path.startsWith("~/") || path.startsWith("~\\")) return path;
115
const base = workspaceRoot.replace(/[/\\]+$/, "");