@devries-cameron20 / t3code-1 / commits / aa35fb3ec6
Fork 0

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

fix(web): folder breadcrumbs navigate to parent folders (#15045)

Co-authored-by: scratchyone <11479077+scratchyone@users.noreply.github.com> Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Co-authored-by: maria-rcks <maria@kuuro.net> Co-authored-by: capy-ai[bot] <230910855+capy-ai[bot]@users.noreply.github.com>

scratchyone committed Oct 15, 2026 at 17:13 UTC aa35fb3ec6b130465223c0b1ac6c10a537b81797
11 files changed +545 -72
apps/server/src/workspace/WorkspaceEntries.test.ts
+24
@@ -134,6 +134,30 @@ it.layer(layerTest, { excludeTestServices: true })("WorkspaceEntries", (it) => {
134 }),
135 );
136
137 + it.effect("lists a host folder and its parent, each from its own root", () =>
138 + // Folder links outside the workspace browse by passing the host folder as
139 + // `cwd`; walking up passes the parent. Each stays bounded by its own root.
140 + Effect.gen(function* () {
141 + const parent = yield* makeTempDir();
142 + const path = yield* Path.Path;
143 + yield* writeTextFile(parent, "linked/notes.md");
144 + yield* writeTextFile(parent, "sibling/readme.md");
145 + const linked = path.join(parent, "linked");
146 +
147 + const workspaceEntries = yield* WorkspaceEntries.WorkspaceEntries;
148 + expect(yield* workspaceEntries.list({ cwd: linked, directoryPath: "" })).toEqual({
149 + entries: [{ path: "notes.md", kind: "file" }],
150 + truncated: false,
151 + });
152 + const up = yield* workspaceEntries.list({ cwd: parent, directoryPath: "" });
153 + expect(up.entries.map((entry) => entry.path).toSorted()).toEqual(["linked", "sibling"]);
154 + const escape = yield* workspaceEntries
155 + .list({ cwd: linked, directoryPath: "../sibling" })
156 + .pipe(Effect.flip);
157 + expect(escape._tag).toBe("WorkspaceEntriesReadDirectoryError");
158 + }),
159 + );
160 +
161 it.effect(
162 "rejects directory traversal, git internals, and symlinks outside the workspace",
163 () =>
apps/web/src/components/ChatView.tsx
+12
@@ -10980,6 +10980,18 @@ export default function ChatView(props: ChatViewProps) {
10980 : 0
10981 }
10982 onOpenFile={openFileSurfaceStable}
10983 + onNavigateFolder={(relativePath, folderTrail, keepSource) =>
10984 + useRightPanelStore
10985 + .getState()
10986 + .navigateFolder(
10987 + activeThreadRef,
10988 + renderedRightPanelSurface.id,
10989 + relativePath,
10990 + folderTrail,
10991 + keepSource,
10992 + )
10993 + }
10994 + folderTrail={renderedRightPanelSurface.folderTrail}
10995 onPendingChange={handleFilePendingChangeStable}
10996 selectedFilePending={
10997 renderedRightPanelSurface.kind === "file" &&
apps/web/src/components/files/FileBreadcrumbs.tsx
+101 -41
@@ -22,19 +22,26 @@ import { cn } from "~/lib/utils";
22 import { isAbsolutePath } from "@t3tools/shared/path";
23
24 import {
25 + breadcrumbPathOf,
26 type FileBreadcrumb,
27 fileBreadcrumbChildren,
28 fileBreadcrumbParent,
29 fileBreadcrumbs,
30 + isListableHostFolder,
31 } from "./filePath";
32 import { useProjectEntriesQuery } from "./projectFilesQueryState";
33
34 interface FileBreadcrumbsProps {
35 readonly cwd: string;
36 readonly environmentId: EnvironmentId;
37 + /** Moves the browser to a folder crumb; `""` is the workspace root. */
38 + readonly onNavigateFolder: (relativePath: string) => void;
39 readonly onOpenFile: (relativePath: string) => void;
40 readonly projectName: string;
41 + /** The current path; `""` is the workspace root. */
42 readonly relativePath: string;
43 + /** The deepest path to show: `relativePath`, or a path inside it the browser came up from. */
44 + readonly trail: string;
45 readonly workspaceMutationId: string | null;
46 }
47
@@ -213,7 +220,8 @@ function BreadcrumbMenuContent(props: {
220 );
221 }
222
216 -function DirectoryBreadcrumb(props: FileBreadcrumbsProps & { readonly crumb: FileBreadcrumb }) {
223 +/** The chevron after a folder crumb lists that folder's entries. */
224 +function FolderContentsMenu(props: FileBreadcrumbsProps & { readonly crumb: FileBreadcrumb }) {
225 const [open, setOpen] = useState(false);
226 const [directoryPath, setDirectoryPath] = useState(props.crumb.path);
227
@@ -229,24 +237,17 @@ function DirectoryBreadcrumb(props: FileBreadcrumbsProps & { readonly crumb: Fil
237
238 return (
239 <Menu open={open} onOpenChange={handleOpenChange}>
232 - <Tooltip>
233 - <TooltipTrigger
234 - render={
235 - <MenuTrigger
236 - render={
237 - <button
238 - type="button"
239 - aria-label={`Browse ${props.crumb.label}`}
240 - className="relative block max-w-40 cursor-pointer rounded-sm px-0.5 text-left text-muted-foreground outline-none pointer-coarse:after:-inset-y-3 pointer-coarse:after:absolute pointer-coarse:after:inset-x-0 hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring data-popup-open:bg-accent data-popup-open:text-foreground"
241 - />
242 - }
243 - />
244 - }
245 - >
246 - <span className="block truncate">{props.crumb.label}</span>
247 - </TooltipTrigger>
248 - <TooltipPopup side="top">{props.crumb.path || props.projectName}</TooltipPopup>
249 - </Tooltip>
240 + <MenuTrigger
241 + render={
242 + <button
243 + type="button"
244 + aria-label={`Browse ${props.crumb.label}`}
245 + className="relative mx-0.5 flex h-5 w-4 shrink-0 cursor-pointer items-center justify-center rounded-sm text-muted-foreground/60 outline-none pointer-coarse:after:absolute pointer-coarse:after:-inset-3 hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring data-popup-open:bg-accent data-popup-open:text-foreground"
246 + />
247 + }
248 + >
249 + <ChevronRightIcon className="size-3.5" />
250 + </MenuTrigger>
251 {open ? (
252 <BreadcrumbMenuContent
253 cwd={props.cwd}
@@ -265,31 +266,90 @@ function DirectoryBreadcrumb(props: FileBreadcrumbsProps & { readonly crumb: Fil
266 );
267 }
268
269 +function FolderBreadcrumb(props: {
270 + readonly crumb: FileBreadcrumb;
271 + /** Below the current folder, kept from where the browser came from. */
272 + readonly descendant: boolean;
273 + readonly onNavigate: (path: string) => void;
274 + readonly projectName: string;
275 +}) {
276 + return (
277 + <Tooltip>
278 + <TooltipTrigger
279 + render={
280 + <button
281 + type="button"
282 + onClick={() => props.onNavigate(props.crumb.path)}
283 + className={cn(
284 + "relative block max-w-40 cursor-pointer rounded-sm px-0.5 text-left outline-none pointer-coarse:after:absolute pointer-coarse:after:inset-x-0 pointer-coarse:after:-inset-y-3 hover:bg-accent hover:text-foreground focus-visible:ring-2 focus-visible:ring-inset focus-visible:ring-ring",
285 + props.descendant ? "text-muted-foreground/70" : "text-muted-foreground",
286 + )}
287 + />
288 + }
289 + >
290 + <span className="block truncate">{props.crumb.label}</span>
291 + </TooltipTrigger>
292 + <TooltipPopup side="top">{props.crumb.path || props.projectName}</TooltipPopup>
293 + </Tooltip>
294 + );
295 +}
296 +
297 +/**
298 + * Each folder crumb moves the browser to that folder, and the chevron after it
299 + * lists the folder's entries. A host path outside the workspace has no contents
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);
304 const breadcrumbs = useMemo(
271 - () => fileBreadcrumbs(props.projectName, props.relativePath),
272 - [props.projectName, props.relativePath],
305 + () => fileBreadcrumbs(props.projectName, props.trail),
306 + [props.projectName, props.trail],
307 );
308 + const currentPath = breadcrumbPathOf(props.relativePath);
309 + const currentIndex = breadcrumbs.findIndex((crumb) => crumb.path === currentPath);
310
275 - return breadcrumbs.map((crumb, index) => (
276 - <div
277 - key={crumb.path || "project"}
278 - className="flex min-w-0 shrink-0 items-center"
279 - data-current-file-crumb={crumb.kind === "file"}
280 - >
281 - {index > 0 ? (
282 - <ChevronRightIcon className="mx-1 size-3.5 shrink-0 text-muted-foreground/60" />
283 - ) : null}
284 - {crumb.kind === "file" ? (
285 - <span aria-current="page">
286 - <BreadcrumbLabel current label={crumb.label} pathLabel={crumb.path} />
287 - </span>
288 - ) : hostPath ? (
289 - <BreadcrumbLabel label={crumb.label} pathLabel={crumb.path} />
290 - ) : (
291 - <DirectoryBreadcrumb {...props} crumb={crumb} />
292 - )}
293 - </div>
294 - ));
311 + return (
312 + <nav aria-label="File path" className="flex h-full">
313 + <ol className="flex items-center">
314 + {breadcrumbs.map((crumb, index) => {
315 + const current = index === currentIndex;
316 + return (
317 + <li
318 + key={crumb.path || "project"}
319 + className="flex min-w-0 shrink-0 items-center"
320 + data-file-crumb
321 + data-current-file-crumb={current}
322 + >
323 + {current ? (
324 + <span aria-current="page">
325 + <BreadcrumbLabel
326 + current
327 + label={crumb.label}
328 + pathLabel={crumb.path || props.projectName}
329 + />
330 + </span>
331 + ) : hostPath && !isListableHostFolder(crumb.path) ? (
332 + <BreadcrumbLabel label={crumb.label} pathLabel={crumb.path} />
333 + ) : (
334 + <FolderBreadcrumb
335 + crumb={crumb}
336 + descendant={index > currentIndex}
337 + onNavigate={props.onNavigateFolder}
338 + projectName={props.projectName}
339 + />
340 + )}
341 + {index === breadcrumbs.length - 1 ? null : hostPath ? (
342 + <ChevronRightIcon
343 + aria-hidden
344 + className="mx-1 size-3.5 shrink-0 text-muted-foreground/60"
345 + />
346 + ) : (
347 + <FolderContentsMenu {...props} crumb={crumb} />
348 + )}
349 + </li>
350 + );
351 + })}
352 + </ol>
353 + </nav>
354 + );
355 }
apps/web/src/components/files/FileBrowserPanel.tsx
+20 -5
@@ -23,6 +23,7 @@ import { readLocalApi } from "~/localApi";
23 import { T3_PIERRE_ICONS } from "~/pierre-icons";
24 import { PIERRE_TREE_UNSAFE_CSS, pierreTreeStyle } from "~/pierre-tree-theme";
25
26 +import { joinHostPath } from "./filePath";
27 import { createFileTreeDragMentionController } from "./fileTreeDragMention";
28 import { areAllDirectoriesExpanded, setAllDirectoriesExpanded } from "./fileTreeExpansion";
29 import { buildFileTreePathUpdates } from "./fileTreePathReconciliation";
@@ -38,6 +39,13 @@ interface FileBrowserPanelProps {
39 /** Bumped when the same path should be revealed again (e.g. re-opened from search). */
40 selectedPathRevealId: number;
41 onOpenFile: (relativePath: string) => void;
42 + /**
43 + * Set when `cwd` is a host folder outside the workspace rather than the
44 + * workspace root. Entries then open and mention as host paths. A host folder can
45 + * be a home directory, so nothing walks it whole: there is no expand-all, and
46 + * search filters the folders already loaded instead of indexing on the server.
47 + */
48 + hostFolder?: boolean;
49 onRefreshSelectedFile?: () => void;
50 workspaceMutationId: string | null;
51 }
@@ -104,7 +112,10 @@ export default function FileBrowserPanel({
112 onOpenFile,
113 onRefreshSelectedFile,
114 workspaceMutationId,
115 + hostFolder = false,
116 }: FileBrowserPanelProps) {
117 + const panelPath = (relativePath: string) =>
118 + hostFolder ? joinHostPath(cwd, relativePath) : relativePath;
119 const { resolvedTheme } = useTheme();
120 const composerRef = useComposerHandleContext();
121 const fileContextMenu = useFileContextMenu(environmentId);
@@ -119,7 +130,10 @@ export default function FileBrowserPanel({
130 } = useDirectoryEntries(environmentId, cwd);
131 const [query, setQuery] = useState("");
132 const [expandAll, setExpandAll] = useState(false);
122 - const pathSearch = useProjectPathSearch({ environmentId, cwd, query: query.slice(0, 256) }, 200);
133 + const pathSearch = useProjectPathSearch(
134 + { environmentId, cwd: hostFolder ? null : cwd, query: query.slice(0, 256) },
135 + 200,
136 + );
137 const entries = useMemo(() => {
138 const result = new Map(directoryEntries.map((entry) => [entry.path, entry]));
139 if (query.trim() && !pathSearch.isPending) {
@@ -172,7 +186,7 @@ export default function FileBrowserPanel({
186 return;
187 }
188 const relativePath = item.path.replace(/\/$/, "");
175 - const mention = serializeComposerFileLink(relativePath);
189 + const mention = serializeComposerFileLink(panelPath(relativePath));
190 const pointer = contextMenuPointerRef.current;
191 const pointerIsFresh = pointer !== null && performance.now() - pointer.at < 1000;
192 const anchorRect = context.anchorElement.getBoundingClientRect();
@@ -248,8 +262,9 @@ export default function FileBrowserPanel({
262 () =>
263 createFileTreeDragMentionController({
264 deselect: (path) => treeModelRef.current?.getItem(path)?.deselect(),
265 + ...(hostFolder ? { mentionPath: (path: string) => joinHostPath(cwd, path) } : {}),
266 }),
252 - [],
267 + [cwd, hostFolder],
268 );
269 const { model } = useFileTree({
270 composition: {
@@ -283,7 +298,7 @@ export default function FileBrowserPanel({
298 const selectedPath = selectedPaths.at(-1)?.replace(/\/$/, "");
299 if (selectedPath && entryKindsRef.current.get(selectedPath) === "file") {
300 treeSelectionPathRef.current = selectedPath;
286 - onOpenFile(selectedPath);
301 + onOpenFile(panelPath(selectedPath));
302 }
303 },
304 paths: [],
@@ -516,7 +531,7 @@ export default function FileBrowserPanel({
531 onValueChange={handleSearchValueChange}
532 onClose={closeSearch}
533 />
519 - {directoryPaths.length > 0 ? (
534 + {directoryPaths.length > 0 && !hostFolder ? (
535 <Tooltip>
536 <TooltipTrigger
537 render={
apps/web/src/components/files/FilePreviewPanel.tsx
+59 -17
@@ -77,6 +77,7 @@ import { BrowserDocumentFrame, isPdfPreviewFile } from "./BrowserDocumentFrame";
77 import { DelimitedTablePreview } from "./DelimitedTablePreview";
78 import FileBrowserPanel from "./FileBrowserPanel";
79 import { FileBreadcrumbs } from "./FileBreadcrumbs";
80 +import { breadcrumbPathOf, retainedBreadcrumbTrail, trailChildOf } from "./filePath";
81 import { FileMarkdownPreview } from "./FileMarkdownPreview";
82 import {
83 type FileCommentAnnotationEntry,
@@ -129,6 +130,10 @@ interface FilePreviewPanelProps {
130 revealLine: number | null;
131 revealRequestId: number;
132 onOpenFile: (relativePath: string) => void;
133 + /** Moves this folder browser to another folder in place; see `navigateFolder`. */
134 + onNavigateFolder: (relativePath: string, folderTrail: string, keepSource: boolean) => void;
135 + /** The deeper path breadcrumbs keep after the browser moved up; see `navigateFolder`. */
136 + folderTrail: string | undefined;
137 onPendingChange: (relativePath: string, pending: boolean) => void;
138 selectedFilePending: boolean;
139 workspaceMutationId: string | null;
@@ -1038,6 +1043,8 @@ export default function FilePreviewPanel({
1043 revealLine,
1044 revealRequestId,
1045 onOpenFile,
1046 + onNavigateFolder,
1047 + folderTrail,
1048 onPendingChange,
1049 selectedFilePending,
1050 workspaceMutationId,
@@ -1087,10 +1094,23 @@ export default function FilePreviewPanel({
1094 // a file surface and the read fails. Keep the breadcrumbs, drop the preview
1095 // pane, and let the tree fill the surface with the folder revealed. Mutation
1096 // refresh stays on so the surface notices if the path becomes a file. A host
1090 - // path cannot be revealed in the workspace tree, so it keeps the read error.
1091 - const isDirectory = file.isNotFile && !isHostFile;
1097 + // folder outside the workspace gets a tree of its own, rooted at that folder.
1098 + // `folderTrail` is set only when crumbs walked the browser up: the deeper path
1099 + // kept for the way back down. The explorer (`""`) shows crumbs only then.
1100 + const breadcrumbPath =
1101 + attachment !== undefined ? null : (relativePath ?? (folderTrail === undefined ? null : ""));
1102 + // A host trail that walked up to the workspace root (`/repo/project` is `""`) no
1103 + // longer passes through the current path, so the crumbs start over there.
1104 + const breadcrumbTrail =
1105 + breadcrumbPath === null ? null : retainedBreadcrumbTrail(folderTrail, breadcrumbPath);
1106 + // The trail only continues below folders, so a surface with one is a folder
1107 + // before its read settles, and walking up never flashes a file preview.
1108 + const isFolder =
1109 + attachment === undefined &&
1110 + (file.isNotFile || (folderTrail !== undefined && file.data === null && file.error === null));
1111 + const hostFolderPath = isFolder && isHostFile ? relativePath : null;
1112 // Everything preview-related keys off previewPath; a folder has no preview.
1093 - const previewPath = isDirectory ? null : relativePath;
1113 + const previewPath = isFolder ? null : relativePath;
1114 const [explorerOpen, setExplorerOpen] = useState(initialExplorerOpen);
1115 const showExplorer = shouldShowFileExplorer({
1116 relativePath: previewPath,
@@ -1162,8 +1182,21 @@ export default function FilePreviewPanel({
1182 !isVideo &&
1183 previewAvailable &&
1184 isBrowserPreviewFile(previewPath);
1185 + // A file keeps its tab; walking up from it opens a folder browser beside it.
1186 + // The trail's end keeps its own spelling (`C:/a` or `C:\a`), so it finds its tab.
1187 + const navigateToFolder = (crumbPath: string) => {
1188 + const path =
1189 + breadcrumbTrail !== null && breadcrumbPathOf(breadcrumbTrail) === crumbPath
1190 + ? breadcrumbTrail
1191 + : crumbPath;
1192 + onNavigateFolder(path, retainedBreadcrumbTrail(breadcrumbTrail ?? undefined, path), !isFolder);
1193 + };
1194 const absolutePath =
1166 - relativePath && attachment === undefined ? resolvePathLinkTarget(relativePath, cwd) : null;
1195 + breadcrumbPath === ""
1196 + ? cwd
1197 + : relativePath && attachment === undefined
1198 + ? resolvePathLinkTarget(relativePath, cwd)
1199 + : null;
1200 const onFilePostRender = useFileLineReveal(relativePath, revealLine, revealRequestId);
1201 useWorkspaceMutationRefresh({
1202 enabled:
@@ -1172,7 +1205,7 @@ export default function FilePreviewPanel({
1205 // Media and PDFs never show their contents, so re-reading them on every
1206 // workspace mutation is waste. A folder named like one still re-reads, so
1207 // it notices when the path becomes a file.
1175 - (isDirectory || (!isMedia && !isPdf)) &&
1208 + (isFolder || (!isMedia && !isPdf)) &&
1209 !selectedFilePending,
1210 mutationId: workspaceMutationId,
1211 refresh: file.refresh,
@@ -1180,11 +1213,13 @@ export default function FilePreviewPanel({
1213 });
1214
1215 useEffect(() => {
1183 - const currentCrumb = breadcrumbRef.current?.querySelector<HTMLElement>(
1184 - "[data-current-file-crumb='true']",
1185 - );
1186 - currentCrumb?.scrollIntoView({ block: "nearest", inline: "end" });
1187 - }, [relativePath]);
1216 + const crumbs = breadcrumbRef.current?.querySelectorAll<HTMLElement>("[data-file-crumb]");
1217 + // Show the deepest crumb when it fits, but never at the cost of the current one.
1218 + crumbs?.[crumbs.length - 1]?.scrollIntoView({ block: "nearest", inline: "end" });
1219 + breadcrumbRef.current
1220 + ?.querySelector<HTMLElement>("[data-current-file-crumb='true']")
1221 + ?.scrollIntoView({ block: "nearest", inline: "nearest" });
1222 + }, [breadcrumbPath, breadcrumbTrail]);
1223
1224 const toggleExplorer = () => {
1225 setExplorerOpen((current) => {
@@ -1250,7 +1285,7 @@ export default function FilePreviewPanel({
1285
1286 return (
1287 <div className="flex min-h-0 flex-1 flex-col overflow-hidden bg-background">
1253 - {relativePath && attachment === undefined ? (
1288 + {breadcrumbPath !== null && breadcrumbTrail !== null ? (
1289 <div className={FILE_SURFACE_SUBHEADER_CLASS} data-surface-subheader>
1290 <ScrollArea
1291 radius="none"
@@ -1264,9 +1299,11 @@ export default function FilePreviewPanel({
1299 <FileBreadcrumbs
1300 cwd={cwd}
1301 environmentId={environmentId}
1302 + onNavigateFolder={navigateToFolder}
1303 onOpenFile={onOpenFile}
1304 projectName={projectName}
1269 - relativePath={relativePath}
1305 + relativePath={breadcrumbPath}
1306 + trail={breadcrumbTrail}
1307 workspaceMutationId={workspaceMutationId}
1308 />
1309 </div>
@@ -1344,7 +1381,7 @@ export default function FilePreviewPanel({
1381 <div
1382 className={cn("min-w-0 flex-1 flex-col overflow-hidden", previewPath ? "flex" : "hidden")}
1383 >
1347 - {isDirectory ? null : relativePath && attachment ? (
1384 + {isFolder ? null : relativePath && attachment ? (
1385 <AttachmentFilePreview
1386 key={`${environmentId}:${attachment.id}`}
1387 name={attachment.name}
@@ -1488,11 +1525,16 @@ export default function FilePreviewPanel({
1525 )}
1526 >
1527 <FileBrowserPanel
1491 - key={`${environmentId}:${cwd}`}
1528 + key={`${environmentId}:${hostFolderPath ?? cwd}`}
1529 environmentId={environmentId}
1493 - cwd={cwd}
1494 - projectName={projectName}
1495 - selectedPath={relativePath}
1530 + cwd={hostFolderPath ?? cwd}
1531 + projectName={hostFolderPath ?? projectName}
1532 + hostFolder={hostFolderPath !== null}
1533 + selectedPath={
1534 + hostFolderPath === null
1535 + ? relativePath
1536 + : trailChildOf(hostFolderPath, breadcrumbTrail ?? hostFolderPath)
1537 + }
1538 selectedPathRevealId={revealRequestId}
1539 onOpenFile={onOpenFile}
1540 workspaceMutationId={workspaceMutationId}
apps/web/src/components/files/filePath.test.ts
+97 -2
@@ -1,6 +1,15 @@
1 import { describe, expect, it } from "vite-plus/test";
2
3 -import { fileBreadcrumbChildren, fileBreadcrumbParent, fileBreadcrumbs } from "./filePath";
3 +import {
4 + breadcrumbPathOf,
5 + fileBreadcrumbChildren,
6 + fileBreadcrumbParent,
7 + fileBreadcrumbs,
8 + isListableHostFolder,
9 + joinHostPath,
10 + retainedBreadcrumbTrail,
11 + trailChildOf,
12 +} from "./filePath";
13
14 describe("fileBreadcrumbs", () => {
15 it("builds project, directory, and file crumbs", () => {
@@ -28,7 +37,7 @@ describe("fileBreadcrumbs", () => {
37 { label: "report.md", path: "/tmp/t3-cleanup/report.md", kind: "file" },
38 ]);
39 expect(fileBreadcrumbs("t3code", "C:\\Temp\\report.md")).toEqual([
31 - { label: "C:", path: "C:", kind: "directory" },
40 + { label: "C:", path: "C:\\", kind: "directory" },
41 { label: "Temp", path: "C:\\Temp", kind: "directory" },
42 { label: "report.md", path: "C:\\Temp\\report.md", kind: "file" },
43 ]);
@@ -40,6 +49,22 @@ describe("fileBreadcrumbs", () => {
49 });
50 });
51
52 +describe("breadcrumbPathOf", () => {
53 + it.each([
54 + ["", ""],
55 + ["src", "src"],
56 + ["src/", "src"],
57 + ["src//components", "src/components"],
58 + ["/tmp/t3-demo/", "/tmp/t3-demo"],
59 + ["/", "/"],
60 + ["C:\\Users\\me\\", "C:\\Users\\me"],
61 + ["C:\\", "C:\\"],
62 + ["\\\\server\\share\\", "\\\\server\\share"],
63 + ])("writes %j as its crumb names it", (path, expected) => {
64 + expect(breadcrumbPathOf(path)).toBe(expected);
65 + });
66 +});
67 +
68 describe("fileBreadcrumbChildren", () => {
69 const entries = [
70 { path: "README.md", kind: "file" as const },
@@ -86,6 +111,76 @@ describe("fileBreadcrumbChildren", () => {
111 });
112 });
113
114 +describe("retainedBreadcrumbTrail", () => {
115 + it.each([
116 + // Walking up keeps the deeper path, all the way to the workspace root.
117 + ["apps/web/src", "apps/web", "apps/web/src"],
118 + ["apps/web/src", "", "apps/web/src"],
119 + // Walking back down inside the trail keeps it too.
120 + ["apps/web/src", "apps/web/src", "apps/web/src"],
121 + // Somewhere else starts over, including a sibling that shares a name prefix.
122 + ["apps/web/src", "apps/mobile", "apps/mobile"],
123 + ["src/lib", "src-old", "src-old"],
124 + ["apps/web", "apps/web/src/main.tsx", "apps/web/src/main.tsx"],
125 + // Workspace and host paths never share a trail.
126 + ["apps/web/src", "/tmp/report", "/tmp/report"],
127 + ["/tmp/report", "", ""],
128 + ["C:\\Temp\\a", "", ""],
129 + // Host folders outside the workspace keep their trail the same way.
130 + ["/Users/me/projects/scope", "/Users/me", "/Users/me/projects/scope"],
131 + ["/Users/me/projects/scope", "/Users/me/proj", "/Users/me/proj"],
132 + ["/Volumes/Work/a", "/Volumes/Work/a/", "/Volumes/Work/a"],
133 + ["C:\\Users\\me\\scope", "C:\\", "C:\\Users\\me\\scope"],
134 + ["C:\\Users\\me\\scope", "C:\\Users", "C:\\Users\\me\\scope"],
135 + ["C:\\Users\\me\\scope", "D:\\", "D:\\"],
136 + ["\\\\nas\\share\\docs\\notes", "\\\\nas\\share", "\\\\nas\\share\\docs\\notes"],
137 + ])("from trail %j to %j keeps %j", (trail, path, expected) => {
138 + expect(retainedBreadcrumbTrail(trail, path)).toBe(expected);
139 + });
140 +
141 + it("starts at the path when nothing came before", () => {
142 + expect(retainedBreadcrumbTrail(undefined, "apps")).toBe("apps");
143 + });
144 +});
145 +
146 +describe("trailChildOf", () => {
147 + it.each([
148 + ["/Users/me", "/Users/me/projects/scope", "projects"],
149 + ["/Users/me/projects/scope", "/Users/me/projects/scope", null],
150 + ["/Users/me", "/Users/meg/a", null],
151 + ["C:\\", "C:\\Users\\me", "Users"],
152 + ["C:\\Users", "C:\\Users\\me\\scope", "me"],
153 + ["\\\\nas\\share", "\\\\nas\\share\\docs\\notes", "docs"],
154 + ])("in %j toward %j selects %j", (folder, trail, expected) => {
155 + expect(trailChildOf(folder, trail)).toBe(expected);
156 + });
157 +});
158 +
159 +describe("joinHostPath", () => {
160 + it.each([
161 + ["/Users/me", "projects/scope", "/Users/me/projects/scope"],
162 + ["/", "Users", "/Users"],
163 + ["C:\\", "Users/me", "C:\\Users\\me"],
164 + ["C:\\Users", "me", "C:\\Users\\me"],
165 + ["\\\\nas\\share", "docs/notes.md", "\\\\nas\\share\\docs\\notes.md"],
166 + ])("joins %j and %j as %j", (folder, relativePath, expected) => {
167 + expect(joinHostPath(folder, relativePath)).toBe(expected);
168 + });
169 +});
170 +
171 +describe("isListableHostFolder", () => {
172 + it.each([
173 + ["/Users", true],
174 + ["C:\\", true],
175 + ["\\\\nas\\share", true],
176 + // A UNC server is not a directory the server can list.
177 + ["\\\\nas", false],
178 + ["apps/web", false],
179 + ])("%j is %j", (path, expected) => {
180 + expect(isListableHostFolder(path)).toBe(expected);
181 + });
182 +});
183 +
184 describe("fileBreadcrumbParent", () => {
185 it.each([
186 ["src/lib", "src"],
apps/web/src/components/files/filePath.ts
+56 -5
@@ -22,14 +22,65 @@ export function fileBreadcrumbs(projectName: string, relativePath: string): File
22 const root = relativePath.startsWith("\\\\") ? "\\\\" : hostPath && separator === "/" ? "/" : "";
23 return [
24 ...(hostPath ? [] : [{ label: projectName, path: "", kind: "project" as const }]),
25 - ...parts.map((part, index) => ({
26 - label: part,
27 - path: root + parts.slice(0, index + 1).join(separator),
28 - kind: index === parts.length - 1 ? ("file" as const) : ("directory" as const),
29 - })),
25 + ...parts.map((part, index) => {
26 + const path = root + parts.slice(0, index + 1).join(separator);
27 + return {
28 + label: part,
29 + // A bare drive (`C:`) means the drive's current directory; its root is `C:\`.
30 + path: /^[A-Za-z]:$/.test(path) ? `${path}\\` : path,
31 + kind: index === parts.length - 1 ? ("file" as const) : ("directory" as const),
32 + };
33 + }),
34 ];
35 }
36
37 +/**
38 + * `relativePath` written the way its own crumb names it, so a link with a
39 + * trailing or repeated separator still finds its crumb.
40 + */
41 +export function breadcrumbPathOf(relativePath: string): string {
42 + return fileBreadcrumbs("", relativePath).at(-1)?.path ?? relativePath;
43 +}
44 +
45 +/**
46 + * Whether a host folder crumb names a directory the server can list. A UNC
47 + * server (`\\server`) is not one; its shares (`\\server\share`) are.
48 + */
49 +export function isListableHostFolder(path: string): boolean {
50 + return isAbsolutePath(path) && !/^\\\\[^\\/]+$/.test(path);
51 +}
52 +
53 +/** Index of `path`'s crumb among `trail`'s crumbs; -1 when the trail does not pass through it. */
54 +function trailCrumbIndex(trail: string, path: string): number {
55 + const crumbPath = breadcrumbPathOf(path);
56 + return fileBreadcrumbs("", trail).findIndex((crumb) => crumb.path === crumbPath);
57 +}
58 +
59 +/**
60 + * The deepest path the breadcrumbs keep showing after the browser moves to `path`.
61 + * Going up keeps the folders below visible so the way back down is one click;
62 + * moving anywhere else starts over at `path`.
63 + */
64 +export function retainedBreadcrumbTrail(trail: string | undefined, path: string): string {
65 + return trail !== undefined && trailCrumbIndex(trail, path) >= 0 ? trail : path;
66 +}
67 +
68 +/** The entry of `folder` that leads toward `trail`; null when the trail ends at the folder. */
69 +export function trailChildOf(folder: string, trail: string): string | null {
70 + const index = trailCrumbIndex(trail, folder);
71 + return index < 0 ? null : (fileBreadcrumbs("", trail)[index + 1]?.label ?? null);
72 +}
73 +
74 +/**
75 + * A host path for `relativePath` (as a host folder's listing names it, with `/`)
76 + * inside host folder `folder`, using the folder's own separator.
77 + */
78 +export function joinHostPath(folder: string, relativePath: string): string {
79 + const separator = isWindowsAbsolutePath(folder) ? "\\" : "/";
80 + const base = folder.endsWith(separator) ? folder : `${folder}${separator}`;
81 + return base + relativePath.split("/").join(separator);
82 +}
83 +
84 export function fileBreadcrumbChildren(
85 entries: readonly ProjectEntry[],
86 directoryPath: string,
apps/web/src/components/files/fileTreeDragMention.test.ts
+13
@@ -38,6 +38,19 @@ describe("createFileTreeDragMentionController", () => {
38 expect(transfer.getData(COMPOSER_MENTION_DRAG_TYPE)).toBe("[architecture](docs/architecture)");
39 });
40
41 + it("mentions rows of a host folder by their host path", () => {
42 + const controller = createFileTreeDragMentionController({
43 + deselect: () => {},
44 + mentionPath: (path) => `/Users/me/scope/${path}`,
45 + });
46 + const transfer = makeTransfer();
47 + controller.handleDragStart({
48 + dataTransfer: transfer,
49 + composedPath: () => [rowNode("notes/")],
50 + });
51 + expect(transfer.getData(COMPOSER_MENTION_DRAG_TYPE)).toBe("[notes](/Users/me/scope/notes)");
52 + });
53 +
54 it("does not tag drags of selected text from the panel chrome", () => {
55 // Only a drag that originates on a tree row is a mention; dragging a text
56 // selection also carries text/plain, and tagging it would drop an invalid
apps/web/src/components/files/fileTreeDragMention.ts
+8 -1
@@ -15,6 +15,8 @@ export interface FileTreeDragStartEvent {
15 export interface FileTreeDragMentionHost {
16 /** Drop the tree's gesture-applied selection of the dragged row. */
17 deselect(treePath: string): void;
18 + /** The path a dragged row mentions; defaults to the tree path itself. */
19 + mentionPath?(treePath: string): string;
20 }
21
22 export interface FileTreeDragMentionController {
@@ -74,7 +76,12 @@ export function createFileTreeDragMentionController(
76 // part of the current selection drags the whole selection.
77 const dragged = selection.includes(itemPath) ? selection : [itemPath];
78 const mentions = dragged
77 - .map((path) => composerMentionFromTreePath(path))
79 + .map((path) => {
80 + const treePath = path.replace(/\/+$/, "");
81 + return composerMentionFromTreePath(
82 + treePath && host.mentionPath ? host.mentionPath(treePath) : path,
83 + );
84 + })
85 .filter((mention): mention is string => mention !== null);
86 if (mentions.length === 0) {
87 return;
apps/web/src/rightPanelStore.test.ts
+95
@@ -682,6 +682,101 @@ describe("rightPanelStore", () => {
682 ).toBe("files");
683 });
684
685 + it("walks a folder browser up and back down in one tab", () => {
686 + const store = useRightPanelStore.getState();
687 + const state = () =>
688 + selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
689 + store.openFile(refA, "README.md");
690 + store.openFile(refA, "apps/web/src");
691 +
692 + store.navigateFolder(refA, "file:apps/web/src", "apps", "apps/web/src");
693 + expect(state().activeSurfaceId).toBe("file:apps");
694 + expect(state().surfaces).toEqual([
695 + expect.objectContaining({ id: "file:README.md" }),
696 + expect.objectContaining({
697 + id: "file:apps",
698 + relativePath: "apps",
699 + folderTrail: "apps/web/src",
700 + }),
701 + ]);
702 +
703 + // The workspace root is the files explorer, still holding the way back down.
704 + store.navigateFolder(refA, "file:apps", "", "apps/web/src");
705 + expect(state().surfaces.map((surface) => surface.id)).toEqual(["file:README.md", "files"]);
706 + expect(state().surfaces[1]).toEqual({
707 + id: "files",
708 + kind: "files",
709 + folderTrail: "apps/web/src",
710 + });
711 +
712 + // Reaching the end of the trail leaves no trail behind.
713 + store.navigateFolder(refA, "files", "apps/web/src", "apps/web/src");
714 + expect(state().activeSurfaceId).toBe("file:apps/web/src");
715 + expect(state().surfaces[1]).toEqual({
716 + id: "file:apps/web/src",
717 + kind: "file",
718 + relativePath: "apps/web/src",
719 + revealLine: null,
720 + revealRequestId: 1,
721 + });
722 + });
723 +
724 + it("switches to a tab that already shows the folder instead of replacing it", () => {
725 + const store = useRightPanelStore.getState();
726 + store.openFile(refA, "apps");
727 + store.openFile(refA, "apps/web/src", 12);
728 +
729 + store.navigateFolder(refA, "file:apps/web/src", "apps", "apps/web/src");
730 + const state = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
731 + expect(state.activeSurfaceId).toBe("file:apps");
732 + expect(state.surfaces).toEqual([
733 + { id: "file:apps", kind: "file", relativePath: "apps", revealLine: null, revealRequestId: 1 },
734 + ]);
735 + });
736 +
737 + it("keeps a file's tab when walking up from it, and comes back to it", () => {
738 + const store = useRightPanelStore.getState();
739 + const state = () =>
740 + selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
741 + store.openFile(refA, "src/app.ts", 40);
742 +
743 + store.navigateFolder(refA, "file:src/app.ts", "src", "src/app.ts", true);
744 + expect(state().activeSurfaceId).toBe("file:src");
745 + expect(state().surfaces).toEqual([
746 + {
747 + id: "file:src/app.ts",
748 + kind: "file",
749 + relativePath: "src/app.ts",
750 + revealLine: 40,
751 + revealRequestId: 1,
752 + },
753 + expect.objectContaining({ id: "file:src", folderTrail: "src/app.ts" }),
754 + ]);
755 +
756 + // The trail's end is the file: its tab comes back as it was, the folder tab goes.
757 + store.navigateFolder(refA, "file:src", "src/app.ts", "src/app.ts");
758 + expect(state().activeSurfaceId).toBe("file:src/app.ts");
759 + expect(state().surfaces).toEqual([
760 + {
761 + id: "file:src/app.ts",
762 + kind: "file",
763 + relativePath: "src/app.ts",
764 + revealLine: 40,
765 + revealRequestId: 1,
766 + },
767 + ]);
768 + });
769 +
770 + it("ignores navigation from a tab that was closed", () => {
771 + const store = useRightPanelStore.getState();
772 + store.openFile(refA, "apps");
773 + const before = selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA);
774 + store.navigateFolder(refA, "file:gone", "", "gone");
775 + expect(selectThreadRightPanelState(useRightPanelStore.getState().byThreadKey, refA)).toBe(
776 + before,
777 + );
778 + });
779 +
780 it("replaces the standalone explorer with peer file surfaces", () => {
781 useRightPanelStore.getState().open(refA, "files");
782 useRightPanelStore.getState().openFile(refA, "src/index.ts");
apps/web/src/rightPanelStore.ts
+60 -1
@@ -53,7 +53,12 @@ export type RightPanelSurface =
53 splitDirection?: "horizontal" | "vertical";
54 }
55 | { id: "diff"; kind: "diff" }
56 - | { id: "files"; kind: "files" }
56 + | {
57 + id: "files";
58 + kind: "files";
59 + /** Set when breadcrumbs moved a folder browser up to the workspace root. */
60 + folderTrail?: string;
61 + }
62 | {
63 id: `file:${string}` | `attachment:${string}`;
64 kind: "file";
@@ -64,6 +69,11 @@ export type RightPanelSurface =
69 /** Present when the file lives in the thread's attachment store rather
70 than at a workspace or host path. */
71 attachment?: ChatFileAttachment;
72 + /**
73 + * Set when breadcrumbs moved a folder browser up from a deeper path: the
74 + * deepest workspace path the breadcrumbs keep offering on the way back down.
75 + */
76 + folderTrail?: string;
77 }
78 | {
79 /**
@@ -152,6 +162,19 @@ interface RightPanelStoreState {
162 renameDevice: (ref: ScopedThreadRef, surfaceId: string, title: string) => void;
163 openBrowser: (ref: ScopedThreadRef, tabId: string | null) => void;
164 openFile: (ref: ScopedThreadRef, relativePath: string, line?: number) => void;
165 + /**
166 + * Moves the folder browser in `surfaceId` to `relativePath` in place, so walking
167 + * the breadcrumbs does not leave a tab behind per folder. `""` is the workspace
168 + * root, which is the files explorer. `folderTrail` is kept for the way back down.
169 + * `keepSource` opens the folder beside the source tab instead, for a file preview.
170 + */
171 + navigateFolder: (
172 + ref: ScopedThreadRef,
173 + surfaceId: string,
174 + relativePath: string,
175 + folderTrail: string,
176 + keepSource?: boolean,
177 + ) => void;
178 openAttachment: (ref: ScopedThreadRef, attachment: ChatFileAttachment) => void;
179 openPullRequest: (
180 ref: ScopedThreadRef,
@@ -471,6 +494,14 @@ export function migratePersistedRightPanelState(persistedState: unknown): {
494 // Removed surfaces: plans render inline, agents in thread lineage.
495 const kind = (surface as { kind?: string }).kind;
496 if (kind === "plan" || kind === "agents") return [];
497 + if (
498 + (surface.kind === "file" || surface.kind === "files") &&
499 + "folderTrail" in surface &&
500 + typeof surface.folderTrail !== "string"
501 + ) {
502 + const { folderTrail: _invalid, ...rest } = surface;
503 + surface = rest;
504 + }
505 if (surface.kind === "file") {
506 const revealLine =
507 typeof surface.revealLine === "number" &&
@@ -741,6 +772,34 @@ export const useRightPanelStore = create<RightPanelStoreState>()(
772 };
773 }),
774 ),
775 + navigateFolder: (ref, surfaceId, relativePath, folderTrail, keepSource = false) =>
776 + set((state) =>
777 + userAction(state, scopedThreadKey(ref), (current) => {
778 + const index = current.surfaces.findIndex((surface) => surface.id === surfaceId);
779 + if (index < 0) return current;
780 + const trail = folderTrail === relativePath ? {} : { folderTrail };
781 + const target: RightPanelSurface =
782 + relativePath === ""
783 + ? { ...singletonSurface("files"), ...trail }
784 + : { ...fileSurface(relativePath, null, 1), ...trail };
785 + const source = current.surfaces[index]!;
786 + // A tab already showing the target wins, so its state is never replaced.
787 + const existing = current.surfaces.some(
788 + (surface, i) => i !== index && surface.id === target.id,
789 + );
790 + const surfaces = current.surfaces.flatMap((surface, i) => {
791 + if (i === index) {
792 + const kept = keepSource ? [source] : [];
793 + return existing ? kept : [...kept, target];
794 + }
795 + // Like openFile: a file surface replaces the standalone explorer.
796 + return !existing && target.kind === "file" && surface.kind === "files"
797 + ? []
798 + : [surface];
799 + });
800 + return { ...current, isOpen: true, activeSurfaceId: target.id, surfaces };
801 + }),
802 + ),
803 openAttachment: (ref, attachment) =>
804 set((state) =>
805 userAction(state, scopedThreadKey(ref), (current) => {