diff --git a/apps/server/src/environment/ServerEnvironment.test.ts b/apps/server/src/environment/ServerEnvironment.test.ts index ee30d98759..d41689915f 100644 --- a/apps/server/src/environment/ServerEnvironment.test.ts +++ b/apps/server/src/environment/ServerEnvironment.test.ts @@ -93,6 +93,7 @@ it.layer(NodeServices.layer)("ServerEnvironmentLive", (it) => { expect(second.capabilities.pullRequests).toBe(true); expect(second.capabilities.threadTitleRegeneration).toBe(true); expect(second.capabilities.agentActivityPublishing).toBe(false); + expect(second.capabilities.fileManagerReveal).toBe(true); }), ); diff --git a/apps/server/src/environment/ServerEnvironment.ts b/apps/server/src/environment/ServerEnvironment.ts index 45dc0ee9cf..d76a16f31d 100644 --- a/apps/server/src/environment/ServerEnvironment.ts +++ b/apps/server/src/environment/ServerEnvironment.ts @@ -152,6 +152,7 @@ export const make = Effect.gen(function* () { threadPinning: true, threadPinReorder: true, threadTitleRegeneration: true, + fileManagerReveal: true, ...(serverSelfUpdate === null ? {} : { serverSelfUpdate }), ...(serverSelfUpdate === "boot-service" ? { serverSelfUpdateProgress: true } : {}), }, diff --git a/apps/web/src/components/ChatMarkdown.tsx b/apps/web/src/components/ChatMarkdown.tsx index 838035d902..90059a942b 100644 --- a/apps/web/src/components/ChatMarkdown.tsx +++ b/apps/web/src/components/ChatMarkdown.tsx @@ -51,6 +51,7 @@ import { resolveExternalWebLinkHost, showExternalLinkContextMenu, } from "./chat/externalLinkContextMenu"; +import { buildFileLinkContextMenuItems } from "./chat/fileLinkContextMenu"; import { hasSpecificPierreIconForFileName, syntheticFileNameForLanguageId } from "../pierre-icons"; import { Tooltip, TooltipPopup, TooltipTrigger } from "./ui/tooltip"; import { Button } from "./ui/button"; @@ -1268,17 +1269,10 @@ const MarkdownFileLink = memo(function MarkdownFileLink({ try { const clicked = await api.contextMenu.show( - [ - ...(canRevealInFileManager - ? ([{ id: "open-in-folder", label: "Open in folder" }] as const) - : []), - { id: "open", label: "Open in editor" }, - ...(onOpenInBrowser - ? ([{ id: "open-in-browser", label: "Open in integrated browser" }] as const) - : []), - { id: "copy-relative", label: "Copy relative path" }, - { id: "copy-full", label: "Copy full path" }, - ] as const, + buildFileLinkContextMenuItems({ + canRevealInFileManager, + canOpenInBrowser: onOpenInBrowser !== undefined, + }), { x: event.clientX, y: event.clientY }, ); @@ -1406,7 +1400,9 @@ function ChatMarkdown({ const availableEditors = serverConfig?.availableEditors ?? []; const openInPreferredEditor = useOpenInPreferredEditor(environmentId, availableEditors); const canRevealInFileManager = - preparedConnection._tag === "Some" && availableEditors.includes("file-manager"); + preparedConnection._tag === "Some" && + serverConfig?.environment.capabilities.fileManagerReveal === true && + availableEditors.includes("file-manager"); const diffThemeName = resolveDiffThemeName(resolvedTheme); const markdownFileLinkMetaByHref = useMemo(() => { const metaByHref = new Map< diff --git a/apps/web/src/components/chat/fileLinkContextMenu.test.ts b/apps/web/src/components/chat/fileLinkContextMenu.test.ts new file mode 100644 index 0000000000..4e338b7d90 --- /dev/null +++ b/apps/web/src/components/chat/fileLinkContextMenu.test.ts @@ -0,0 +1,33 @@ +import { describe, expect, it } from "vite-plus/test"; + +import { buildFileLinkContextMenuItems } from "./fileLinkContextMenu"; + +describe("chat file link context menu", () => { + it("puts Open in folder first when the environment supports it", () => { + expect( + buildFileLinkContextMenuItems({ + canRevealInFileManager: true, + canOpenInBrowser: false, + }), + ).toEqual([ + { id: "open-in-folder", label: "Open in folder" }, + { id: "open", label: "Open in editor" }, + { id: "copy-relative", label: "Copy relative path" }, + { id: "copy-full", label: "Copy full path" }, + ]); + }); + + it("hides Open in folder when the environment does not support it", () => { + expect( + buildFileLinkContextMenuItems({ + canRevealInFileManager: false, + canOpenInBrowser: true, + }), + ).toEqual([ + { id: "open", label: "Open in editor" }, + { id: "open-in-browser", label: "Open in integrated browser" }, + { id: "copy-relative", label: "Copy relative path" }, + { id: "copy-full", label: "Copy full path" }, + ]); + }); +}); diff --git a/apps/web/src/components/chat/fileLinkContextMenu.ts b/apps/web/src/components/chat/fileLinkContextMenu.ts new file mode 100644 index 0000000000..a67da62682 --- /dev/null +++ b/apps/web/src/components/chat/fileLinkContextMenu.ts @@ -0,0 +1,25 @@ +import type { ContextMenuItem } from "@t3tools/contracts"; + +export type FileLinkContextMenuAction = + | "open-in-folder" + | "open" + | "open-in-browser" + | "copy-relative" + | "copy-full"; + +export function buildFileLinkContextMenuItems(input: { + readonly canRevealInFileManager: boolean; + readonly canOpenInBrowser: boolean; +}): readonly ContextMenuItem[] { + return [ + ...(input.canRevealInFileManager + ? ([{ id: "open-in-folder", label: "Open in folder" }] as const) + : []), + { id: "open", label: "Open in editor" }, + ...(input.canOpenInBrowser + ? ([{ id: "open-in-browser", label: "Open in integrated browser" }] as const) + : []), + { id: "copy-relative", label: "Copy relative path" }, + { id: "copy-full", label: "Copy full path" }, + ]; +} diff --git a/packages/contracts/src/environment.ts b/packages/contracts/src/environment.ts index 1777bcebc2..2f35ddd15f 100644 --- a/packages/contracts/src/environment.ts +++ b/packages/contracts/src/environment.ts @@ -67,6 +67,9 @@ export const ExecutionEnvironmentCapabilities = Schema.Struct({ /** Server understands regenerateTitle on thread.meta.update. Absent on older servers, so clients hide the action instead of sending it. */ threadTitleRegeneration: Schema.optionalKey(Schema.Boolean), + /** Server understands shell.revealInFileManager. Absent on older servers, + so clients hide the action instead of sending an unsupported RPC. */ + fileManagerReveal: Schema.optionalKey(Schema.Boolean), /** The update path clients should offer for this server. Absent on servers that must be relaunched manually (dev checkouts, Windows foreground runs, pre-update servers). */