Compare commits

...
Author SHA1 Message Date
Yash Singh 327ada5ecc Remove remote download-and-reveal flow
- حذف desktop IPC and shell support for temporary file downloads
- Simplify asset URL handling to treat workspace files uniformly
- Update markdown file links to use platform-specific reveal labels
2026-07-25 19:08:21 -05:00
Yash Singh daee2c3098 support remote environments 2026-07-24 12:11:50 -05:00
Yash Singh c877be3931 Merge remote-tracking branch 'origin/main' into t3code/show-in-finder 2026-07-21 22:02:21 -05:00
Yash Singh 708f9da5e1 feat: show in finder btn for file pills 2026-07-21 22:02:05 -05:00
8 changed files with 274 additions and 10 deletions

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,
+95 -4
View File
@@ -9,7 +9,11 @@ import {
Minimize2Icon,
WrapTextIcon,
} from "lucide-react";
import type { ScopedThreadRef, ServerProviderSkill } from "@t3tools/contracts";
import type {
ExecutionEnvironmentPlatformOs,
ScopedThreadRef,
ServerProviderSkill,
} from "@t3tools/contracts";
import {
isAtomCommandInterrupted,
squashAtomCommandFailure,
@@ -74,6 +78,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 +748,8 @@ interface MarkdownFileLinkProps {
theme: "light" | "dark";
threadRef?: ScopedThreadRef | undefined;
onOpen: (targetPath: string) => Promise<AtomCommandResult<unknown, unknown>>;
onShowInFinder: (targetPath: string) => Promise<AtomCommandResult<unknown, unknown>>;
fileManagerLabel: string;
onOpenInBrowser?: (() => Promise<AtomCommandResult<unknown, unknown>>) | undefined;
className?: string | undefined;
}
@@ -751,6 +758,12 @@ const MARKDOWN_LINK_HREF_PATTERN = /\[[^\]]*]\(([^)\s]+)(?:\s+["'][^"']*["'])?\)
const MARKDOWN_FILE_LINK_CLASS_NAME =
"chat-markdown-file-link cursor-pointer transition-colors hover:bg-accent/70";
function fileManagerLabelForPlatform(platform: ExecutionEnvironmentPlatformOs | undefined): string {
if (platform === "darwin") return "Show in Finder";
if (platform === "windows") return "Show in File Explorer";
return "Show in Files";
}
function pathParentSegments(path: string): string[] {
const normalized = path.replaceAll("\\", "/");
const segments = normalized.split("/").filter((segment) => segment.length > 0);
@@ -1022,6 +1035,8 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
theme,
threadRef,
onOpen,
onShowInFinder,
fileManagerLabel,
onOpenInBrowser,
className,
}: MarkdownFileLinkProps) {
@@ -1068,6 +1083,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 ${fileManagerLabel.toLowerCase()}`,
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 ${fileManagerLabel.toLowerCase()}`,
description: cause instanceof Error ? cause.message : "An error occurred.",
}),
);
}
})();
}, [fileManagerLabel, iconPath, onShowInFinder]);
const handleOpenInBrowser = useCallback(() => {
if (!onOpenInBrowser) {
return;
@@ -1162,6 +1209,10 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
: []),
{ id: "copy-relative", label: "Copy relative path" },
{ id: "copy-full", label: "Copy full path" },
{
id: "show-in-finder",
label: fileManagerLabel,
},
] as const,
{ x: event.clientX, y: event.clientY },
);
@@ -1180,6 +1231,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 +1243,16 @@ const MarkdownFileLink = memo(function MarkdownFileLink({
);
}
},
[displayPath, handleCopy, handleOpenInBrowser, handleOpenInEditor, onOpenInBrowser, targetPath],
[
displayPath,
handleCopy,
handleOpenInBrowser,
handleOpenInEditor,
handleShowInFinder,
fileManagerLabel,
onOpenInBrowser,
targetPath,
],
);
return (
@@ -1242,6 +1306,8 @@ function areMarkdownFileLinkPropsEqual(
previous.theme === next.theme &&
previous.threadRef === next.threadRef &&
previous.onOpen === next.onOpen &&
previous.onShowInFinder === next.onShowInFinder &&
previous.fileManagerLabel === next.fileManagerLabel &&
previous.onOpenInBrowser === next.onOpenInBrowser &&
previous.className === next.className
);
@@ -1264,13 +1330,34 @@ 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));
const fileEnvironmentId = threadRef?.environmentId ?? environmentId;
const serverConfig = useAtomValue(serverEnvironment.configValueAtom(fileEnvironmentId));
const openInPreferredEditor = useOpenInPreferredEditor(
environmentId,
fileEnvironmentId,
serverConfig?.availableEditors ?? [],
);
const showFileInFinder = useCallback(
(targetPath: string) => {
if (fileEnvironmentId === null) {
return Promise.resolve(
AsyncResult.failure<void, Error>(
Cause.fail(new Error("Cannot show the file because no environment is selected.")),
),
);
}
return revealInFileManager({
environmentId: fileEnvironmentId,
input: { path: targetPath },
});
},
[fileEnvironmentId, revealInFileManager],
);
const fileManagerLabel = fileManagerLabelForPlatform(serverConfig?.environment.platform.os);
const diffThemeName = resolveDiffThemeName(resolvedTheme);
const markdownFileLinkMetaByHref = useMemo(() => {
const metaByHref = new Map<
@@ -1492,6 +1579,8 @@ function ChatMarkdown({
theme={resolvedTheme}
threadRef={threadRef}
onOpen={openInPreferredEditor}
onShowInFinder={showFileInFinder}
fileManagerLabel={fileManagerLabel}
onOpenInBrowser={
threadRef &&
isPreviewSupportedInRuntime() &&
@@ -1547,7 +1636,9 @@ function ChatMarkdown({
openInPreferredEditor,
openExternalLinkInPreview,
openMarkdownFileInPreview,
fileManagerLabel,
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,