feat: show in finder btn for file pills

This commit is contained in:
Yash Singh committed 2026-07-21 22:02:05 -05:00
1 parent 5d34f9ff23
commit 708f9da5e1
8 files changed
+258 -7

No files matched your search

@@ -92,11 +92,67 @@ it.effect("launches the default browser through the platform command", () => {
);
});
it.effect("reveals a file in Finder on macOS", () => {
let spawned: ChildProcess.StandardCommand | undefined;
let didUnref = false;
const target = "/tmp/project with spaces/src/odd '✨' file.ts";
return Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
yield* launcher.revealInFileManager(target);
assert.ok(spawned);
assert.equal(spawned.command, "open");
assert.deepEqual(spawned.args, ["-R", target]);
assert.equal(spawned.options.detached, true);
assert.equal(didUnref, true);
}).pipe(
Effect.provide(
testLayer({
platform: "darwin",
onSpawn: (command) => {
spawned = command;
},
onUnref: () => {
didUnref = true;
},
}),
),
);
});
it.effect("reveals a file in Explorer on Windows", () => {
let spawned: ChildProcess.StandardCommand | undefined;
const target = `C:/project with spaces/src/odd '✨' file.ts`;
const windowsTarget = String.raw`C:\project with spaces\src\odd '✨' file.ts`;
return Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
yield* launcher.revealInFileManager(target);
assert.ok(spawned);
assert.equal(spawned.command, "explorer");
assert.deepEqual(spawned.args, ["/select,", windowsTarget]);
assert.equal(spawned.options.detached, true);
}).pipe(
Effect.provide(
testLayer({
platform: "win32",
onSpawn: (command) => {
spawned = command;
},
}),
),
);
});
it.effect("launches an installed editor with platform-safe arguments", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" });
const binDir = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-editors-",
});
yield* fileSystem.writeFileString(path.join(binDir, "code.CMD"), "@echo off\r\n");
let spawned: ChildProcess.StandardCommand | undefined;
@@ -134,7 +190,9 @@ it.effect("discovers editors through the service API", () =>
Effect.gen(function* () {
const fileSystem = yield* FileSystem.FileSystem;
const path = yield* Path.Path;
const binDir = yield* fileSystem.makeTempDirectoryScoped({ prefix: "t3-editors-" });
const binDir = yield* fileSystem.makeTempDirectoryScoped({
prefix: "t3-editors-",
});
yield* fileSystem.writeFileString(path.join(binDir, "code.CMD"), "@echo off\r\n");
yield* fileSystem.writeFileString(path.join(binDir, "explorer.CMD"), "@echo off\r\n");
@@ -159,7 +217,10 @@ it.effect("rejects unknown editors through the service API", () =>
Effect.gen(function* () {
const launcher = yield* ExternalLauncher.ExternalLauncher;
const error = yield* launcher
.launchEditor({ editor: "missing-editor" as never, cwd: "/tmp/workspace" })
.launchEditor({
editor: "missing-editor" as never,
cwd: "/tmp/workspace",
})
.pipe(Effect.flip);
assert.instanceOf(error, ExternalLauncher.ExternalLauncherUnknownEditorError);
assert.equal(error.editor, "missing-editor");
+64 -2
View File
@@ -313,6 +313,8 @@ export class ExternalLauncher extends Context.Service<
* Launches the editor as a detached process so server startup is not blocked.
*/
readonly launchEditor: (input: LaunchEditorInput) => Effect.Effect<void, ExternalLauncherError>;
/** Reveal a workspace path in the host platform's file manager. */
readonly revealInFileManager: (target: string) => Effect.Effect<void, ExternalLauncherError>;
}
>()("t3/process/externalLauncher") {}
@@ -332,7 +334,9 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
});
const editorDef = EDITORS.find((editor) => editor.id === input.editor);
if (!editorDef) {
return yield* new ExternalLauncherUnknownEditorError({ editor: input.editor });
return yield* new ExternalLauncherUnknownEditorError({
editor: input.editor,
});
}
if (editorDef.commands) {
@@ -349,7 +353,9 @@ const resolveEditorLaunch = Effect.fn("resolveEditorLaunch")(function* (
}
if (editorDef.id !== "file-manager") {
return yield* new ExternalLauncherUnsupportedEditorError({ editor: input.editor });
return yield* new ExternalLauncherUnsupportedEditorError({
editor: input.editor,
});
}
return {
@@ -430,6 +436,57 @@ const launchEditorProcess = Effect.fn("externalLauncher.launchEditorProcess")(fu
);
});
const resolveFileManagerRevealLaunch = Effect.fn("externalLauncher.resolveFileManagerRevealLaunch")(
function* (target: string): Effect.fn.Return<ProcessLaunch, never, Path.Path> {
const platform = yield* HostProcessPlatform;
const path = yield* Path.Path;
switch (platform) {
case "darwin":
return {
command: "open",
args: ["-R", target],
options: DETACHED_IGNORE_STDIO_OPTIONS,
};
case "win32": {
const windowsTarget = target.replaceAll("/", "\\");
return {
command: "explorer",
args: ["/select,", windowsTarget],
options: DETACHED_IGNORE_STDIO_OPTIONS,
};
}
default:
return {
command: "xdg-open",
args: [path.dirname(target)],
options: DETACHED_IGNORE_STDIO_OPTIONS,
};
}
},
);
const revealInFileManager = Effect.fn("externalLauncher.revealInFileManager")(function* (
target: string,
): Effect.fn.Return<
void,
ExternalLauncherError,
ChildProcessSpawner.ChildProcessSpawner | Path.Path
> {
const launch = yield* resolveFileManagerRevealLaunch(target);
return yield* launchAndUnref(
launch,
(cause) =>
new ExternalLauncherEditorSpawnError({
editor: "file-manager",
target,
command: launch.command,
args: launch.args,
cause,
}),
);
});
export const make = Effect.gen(function* () {
const spawner = yield* ChildProcessSpawner.ChildProcessSpawner;
const fileSystem = yield* FileSystem.FileSystem;
@@ -457,6 +514,11 @@ export const make = Effect.gen(function* () {
),
),
),
revealInFileManager: (target) =>
revealInFileManager(target).pipe(
Effect.provideService(ChildProcessSpawner.ChildProcessSpawner, spawner),
Effect.provideService(Path.Path, path),
),
});
});
+27
View File
@@ -4798,6 +4798,33 @@ it.layer(NodeServices.layer)("server router seam", (it) => {
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
it.effect("routes websocket rpc shell.revealInFileManager", () =>
Effect.gen(function* () {
let revealedPath: string | null = null;
yield* buildAppUnderTest({
layers: {
externalLauncher: {
revealInFileManager: (path) =>
Effect.sync(() => {
revealedPath = path;
}),
},
},
});
const wsUrl = yield* getWsServerUrl("/ws");
yield* Effect.scoped(
withWsRpcClient(wsUrl, (client) =>
client[WS_METHODS.shellRevealInFileManager]({
path: "/tmp/project/src/index.ts",
}),
),
);
assert.equal(revealedPath, "/tmp/project/src/index.ts");
}).pipe(Effect.provide(NodeHttpServer.layerTest)),
);
it.effect("routes websocket rpc git methods", () =>
Effect.gen(function* () {
yield* buildAppUnderTest({
+7
View File
@@ -315,6 +315,7 @@ const RPC_REQUIRED_SCOPE = new Map<string, AuthEnvironmentScope>([
[WS_METHODS.projectsSearchEntries, AuthOrchestrationReadScope],
[WS_METHODS.projectsWriteFile, AuthOrchestrationOperateScope],
[WS_METHODS.shellOpenInEditor, AuthOrchestrationOperateScope],
[WS_METHODS.shellRevealInFileManager, AuthOrchestrationOperateScope],
[WS_METHODS.filesystemBrowse, AuthOrchestrationReadScope],
[WS_METHODS.assetsCreateUrl, AuthOrchestrationReadScope],
[WS_METHODS.subscribeVcsStatus, AuthOrchestrationReadScope],
@@ -1675,6 +1676,12 @@ const makeWsRpcLayer = (
observeRpcEffect(WS_METHODS.shellOpenInEditor, externalLauncher.launchEditor(input), {
"rpc.aggregate": "workspace",
}),
[WS_METHODS.shellRevealInFileManager]: (input) =>
observeRpcEffect(
WS_METHODS.shellRevealInFileManager,
externalLauncher.revealInFileManager(input.path),
{ "rpc.aggregate": "workspace" },
),
[WS_METHODS.filesystemBrowse]: (input) =>
observeRpcEffect(
WS_METHODS.filesystemBrowse,
+79 -1
View File
@@ -74,6 +74,7 @@ import { serverEnvironment } from "../state/server";
import { assetEnvironment } from "../state/assets";
import { usePreparedConnection } from "../state/session";
import { previewEnvironment } from "../state/preview";
import { shellEnvironment } from "../state/shell";
import { useAtomCommand } from "../state/use-atom-command";
import { useAtomQueryRunner } from "../state/use-atom-query-runner";
import { isPreviewSupportedInRuntime } from "../previewStateStore";
@@ -743,6 +744,7 @@ interface MarkdownFileLinkProps {
theme: "light" | "dark";
threadRef?: ScopedThreadRef | undefined;
onOpen: (targetPath: string) => Promise<AtomCommandResult<unknown, unknown>>;
onShowInFinder: (targetPath: string) => Promise<AtomCommandResult<unknown, unknown>>;
onOpenInBrowser?: (() => Promise<AtomCommandResult<unknown, unknown>>) | undefined;
className?: string | undefined;
}
@@ -1022,6 +1024,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
theme,
threadRef,
onOpen,
onShowInFinder,
onOpenInBrowser,
className,
}: MarkdownFileLinkProps) {
@@ -1068,6 +1071,38 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
useRightPanelStore.getState().openFile(threadRef, workspaceRelativePath, line);
}, [handleOpenInEditor, line, threadRef, workspaceRelativePath]);
const handleShowInFinder = useCallback(() => {
void (async () => {
try {
const result = await onShowInFinder(iconPath);
if (result._tag === "Success" || isAtomCommandInterrupted(result)) {
return;
}
reportMarkdownActionFailure(
{ operation: "show-file-in-finder", target: iconPath },
result.cause,
);
const error = squashAtomCommandFailure(result);
toastManager.add(
stackedThreadToast({
type: "error",
title: "Unable to show file in Finder",
description: error instanceof Error ? error.message : "An error occurred.",
}),
);
} catch (cause) {
reportMarkdownActionFailure({ operation: "show-file-in-finder", target: iconPath }, cause);
toastManager.add(
stackedThreadToast({
type: "error",
title: "Unable to show file in Finder",
description: cause instanceof Error ? cause.message : "An error occurred.",
}),
);
}
})();
}, [iconPath, onShowInFinder]);
const handleOpenInBrowser = useCallback(() => {
if (!onOpenInBrowser) {
return;
@@ -1154,6 +1189,7 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
if (!api) return;
try {
const platform = navigator.platform.toLowerCase();
const clicked = await api.contextMenu.show(
[
{ id: "open", label: "Open in editor" },
@@ -1162,6 +1198,14 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
: []),
{ id: "copy-relative", label: "Copy relative path" },
{ id: "copy-full", label: "Copy full path" },
{
id: "show-in-finder",
label: platform.includes("mac")
? "Show in Finder"
: platform.includes("win")
? "Show in File Explorer"
: "Show in Files",
},
] as const,
{ x: event.clientX, y: event.clientY },
);
@@ -1180,6 +1224,10 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
}
if (clicked === "copy-full") {
handleCopy(targetPath, "Full path");
return;
}
if (clicked === "show-in-finder") {
handleShowInFinder();
}
} catch (cause) {
reportMarkdownActionFailure(
@@ -1188,7 +1236,15 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
);
}
},
[displayPath, handleCopy, handleOpenInBrowser, handleOpenInEditor, onOpenInBrowser, targetPath],
[
displayPath,
handleCopy,
handleOpenInBrowser,
handleOpenInEditor,
handleShowInFinder,
onOpenInBrowser,
targetPath,
],
);
return (
@@ -1242,6 +1298,7 @@ function areMarkdownFileLinkPropsEqual(
previous.theme === next.theme &&
previous.threadRef === next.threadRef &&
previous.onOpen === next.onOpen &&
previous.onShowInFinder === next.onShowInFinder &&
previous.onOpenInBrowser === next.onOpenInBrowser &&
previous.className === next.className
);
@@ -1264,6 +1321,9 @@ function ChatMarkdown({
const openPreview = useAtomCommand(previewEnvironment.open, {
reportFailure: false,
});
const revealInFileManager = useAtomCommand(shellEnvironment.revealInFileManager, {
reportFailure: false,
});
const preparedConnection = usePreparedConnection(threadRef?.environmentId ?? null);
const environmentId = useActiveEnvironmentId();
const serverConfig = useAtomValue(serverEnvironment.configValueAtom(environmentId));
@@ -1271,6 +1331,22 @@ function ChatMarkdown({
environmentId,
serverConfig?.availableEditors ?? [],
);
const showFileInFinder = useCallback(
(targetPath: string) => {
if (environmentId === null) {
return Promise.resolve(
AsyncResult.failure<void, Error>(
Cause.fail(new Error("Cannot show the file because no environment is selected.")),
),
);
}
return revealInFileManager({
environmentId,
input: { path: targetPath },
});
},
[environmentId, revealInFileManager],
);
const diffThemeName = resolveDiffThemeName(resolvedTheme);
const markdownFileLinkMetaByHref = useMemo(() => {
const metaByHref = new Map<
@@ -1492,6 +1568,7 @@ function ChatMarkdown({
theme={resolvedTheme}
threadRef={threadRef}
onOpen={openInPreferredEditor}
onShowInFinder={showFileInFinder}
onOpenInBrowser={
threadRef &&
isPreviewSupportedInRuntime() &&
@@ -1548,6 +1625,7 @@ function ChatMarkdown({
openExternalLinkInPreview,
openMarkdownFileInPreview,
resolvedTheme,
showFileInFinder,
skills,
text,
threadRef,
@@ -12,5 +12,9 @@ export function createShellEnvironmentAtoms<R, E>(
label: "environment-data:shell:open-in-editor",
tag: WS_METHODS.shellOpenInEditor,
}),
revealInFileManager: createEnvironmentRpcCommand(runtime, {
label: "environment-data:shell:reveal-in-file-manager",
tag: WS_METHODS.shellRevealInFileManager,
}),
};
}
+5
View File
@@ -50,6 +50,11 @@ export const LaunchEditorInput = Schema.Struct({
});
export type LaunchEditorInput = typeof LaunchEditorInput.Type;
export const RevealPathInput = Schema.Struct({
path: TrimmedNonEmptyString,
});
export type RevealPathInput = typeof RevealPathInput.Type;
export class ExternalLauncherUnknownEditorError extends Schema.TaggedErrorClass<ExternalLauncherUnknownEditorError>()(
"ExternalLauncherUnknownEditorError",
{
+8 -1
View File
@@ -2,7 +2,7 @@ import * as Schema from "effect/Schema";
import * as Rpc from "effect/unstable/rpc/Rpc";
import * as RpcGroup from "effect/unstable/rpc/RpcGroup";
import { ExternalLauncherError, LaunchEditorInput } from "./editor.ts";
import { ExternalLauncherError, LaunchEditorInput, RevealPathInput } from "./editor.ts";
import {
AuthAccessStreamError,
AuthAccessStreamEvent,
@@ -156,6 +156,7 @@ export const WS_METHODS = {
// Shell methods
shellOpenInEditor: "shell.openInEditor",
shellRevealInFileManager: "shell.revealInFileManager",
// Filesystem methods
filesystemBrowse: "filesystem.browse",
@@ -390,6 +391,11 @@ export const WsShellOpenInEditorRpc = Rpc.make(WS_METHODS.shellOpenInEditor, {
error: Schema.Union([ExternalLauncherError, EnvironmentAuthorizationError]),
});
export const WsShellRevealInFileManagerRpc = Rpc.make(WS_METHODS.shellRevealInFileManager, {
payload: RevealPathInput,
error: Schema.Union([ExternalLauncherError, EnvironmentAuthorizationError]),
});
export const WsFilesystemBrowseRpc = Rpc.make(WS_METHODS.filesystemBrowse, {
payload: FilesystemBrowseInput,
success: FilesystemBrowseResult,
@@ -712,6 +718,7 @@ export const WsRpcGroup = RpcGroup.make(
WsProjectsSearchEntriesRpc,
WsProjectsWriteFileRpc,
WsShellOpenInEditorRpc,
WsShellRevealInFileManagerRpc,
WsFilesystemBrowseRpc,
WsAssetsCreateUrlRpc,
WsSubscribeVcsStatusRpc,