Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 27 additions & 6 deletions apps/web/src/components/ChatMarkdown.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,8 @@ vi.mock("../state/entities", () => ({
useProjects: () => [],
useServerConfigs: () => new Map(),
}));
vi.mock("../remoteOpen", () => ({
vi.mock("../remoteOpen", async (importOriginal) => ({
...(await importOriginal<typeof import("../remoteOpen")>()),
useRemoteOpenResolution: () => ({ state: { mode: "local-exec" }, isResolved: true }),
}));
vi.mock("../editorPreferences", () => ({
Expand Down Expand Up @@ -382,20 +383,40 @@ describe("canUseMarkdownFileShellActions", () => {
const environmentId = EnvironmentId.make("environment-1");

it("allows editor and file manager actions for local environments", () => {
expect(canUseMarkdownFileShellActions(environmentId, "local-exec", true)).toBe(true);
expect(canUseMarkdownFileShellActions(environmentId, { mode: "local-exec" }, true)).toBe(true);
});

it("keeps shell actions for WSL environments, whose server runs on the same machine", () => {
expect(
canUseMarkdownFileShellActions(
environmentId,
{ mode: "remote-links", host: { kind: "wsl", host: "Ubuntu" } },
true,
),
).toBe(true);
});

it("hides shell actions until the environment mode is resolved", () => {
expect(canUseMarkdownFileShellActions(environmentId, "local-exec", false)).toBe(false);
expect(canUseMarkdownFileShellActions(environmentId, { mode: "local-exec" }, false)).toBe(
false,
);
});

it("hides editor and file manager actions for remote environments", () => {
expect(canUseMarkdownFileShellActions(environmentId, "remote-links", true)).toBe(false);
expect(canUseMarkdownFileShellActions(environmentId, "remote-unavailable", true)).toBe(false);
expect(
canUseMarkdownFileShellActions(
environmentId,
{ mode: "remote-links", host: { kind: "ssh-alias", host: "devbox" } },
true,
),
).toBe(false);
expect(
canUseMarkdownFileShellActions(environmentId, { mode: "remote-unavailable" }, true),
).toBe(false);
});

it("hides shell actions when no environment owns the markdown", () => {
expect(canUseMarkdownFileShellActions(null, "local-exec", true)).toBe(false);
expect(canUseMarkdownFileShellActions(null, { mode: "local-exec" }, true)).toBe(false);
});
});

Expand Down
8 changes: 4 additions & 4 deletions apps/web/src/components/ChatMarkdown.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ import {
import { readLocalApi } from "../localApi";
import { useAssetUrlRefresh, useAssetUrlState } from "../assets/assetUrls";
import { cn } from "../lib/utils";
import { useRemoteOpenResolution, type RemoteOpenMode } from "../remoteOpen";
import { canExecOnServer, useRemoteOpenResolution, type RemoteOpenState } from "../remoteOpen";
import { useRightPanelStore } from "../rightPanelStore";
import { readThreadShell, useProjects } from "../state/entities";
import { serverEnvironment } from "../state/server";
Expand Down Expand Up @@ -239,10 +239,10 @@ export interface ChatMarkdownContextReference {

export function canUseMarkdownFileShellActions(
environmentId: EnvironmentId | null,
remoteOpenMode: RemoteOpenMode,
remoteOpenState: RemoteOpenState,
isRemoteOpenResolved: boolean,
): boolean {
return environmentId !== null && isRemoteOpenResolved && remoteOpenMode === "local-exec";
return environmentId !== null && isRemoteOpenResolved && canExecOnServer(remoteOpenState);
Comment thread
cursor[bot] marked this conversation as resolved.
Resolved
}

export function hasMarkdownFilePrimaryAction(input: {
Expand Down Expand Up @@ -2275,7 +2275,7 @@ function useChatMarkdownState({
const remoteOpen = useRemoteOpenResolution(environmentId);
const canUseShellActions = canUseMarkdownFileShellActions(
environmentId,
remoteOpen.state.mode,
remoteOpen.state,
remoteOpen.isResolved,
);
const preparedConnection = usePreparedConnection(environmentId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@ vi.mock("../state/entities", () => ({
useProjects: () => [],
useServerConfigs: () => new Map(),
}));
vi.mock("../remoteOpen", () => ({
vi.mock("../remoteOpen", async (importOriginal) => ({
...(await importOriginal<typeof import("../remoteOpen")>()),
useRemoteOpenResolution: () => ({ state: { mode: "local-exec" }, isResolved: true }),
}));
vi.mock("../editorPreferences", () => ({
Expand Down
4 changes: 0 additions & 4 deletions apps/web/src/components/ChatView.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,6 @@ import { useKnownTerminalSessions, useThreadRunningTerminalIds } from "../state/
import { useEnvironmentQuery } from "../state/query";
import {
environmentServerConfigsAtom,
primaryServerAvailableEditorsAtom,
primaryServerKeybindingsAtom,
serverEnvironment,
} from "../state/server";
Expand Down Expand Up @@ -3662,7 +3661,6 @@ export default function ChatView(props: ChatViewProps) {
resourceKey: `git-status:${activeThreadKey ?? ""}:${gitStatusCwd ?? ""}`,
});
const keybindings = useAtomValue(primaryServerKeybindingsAtom);
const availableEditors = useAtomValue(primaryServerAvailableEditorsAtom);
const manualCompactionProviderAvailable = useMemo(
() =>
hasAvailableCompactionProvider({
Expand Down Expand Up @@ -9735,7 +9733,6 @@ export default function ChatView(props: ChatViewProps) {
threadRef={activeThreadRef}
composerDraftTarget={composerDraftTarget}
keybindings={keybindings}
availableEditors={availableEditors}
relativePath={
renderedRightPanelSurface.kind === "file"
? renderedRightPanelSurface.relativePath
Expand Down Expand Up @@ -9835,7 +9832,6 @@ export default function ChatView(props: ChatViewProps) {
activeProject ? (lastInvokedScriptByProjectId[activeProject.id] ?? null) : null
}
keybindings={keybindings}
availableEditors={availableEditors}
rightPanelOpen={rightPanelOpen}
gitCwd={gitCwd}
onNewThreadInProject={handleNewThreadInActiveProject}
Expand Down
62 changes: 1 addition & 61 deletions apps/web/src/components/chat/ChatHeader.test.ts
Original file line number Diff line number Diff line change
@@ -1,66 +1,6 @@
import { EnvironmentId } from "@t3tools/contracts";
import { describe, expect, it } from "vite-plus/test";

import { resolveRenameCommit, shouldShowOpenInPicker } from "./ChatHeader";

describe("shouldShowOpenInPicker", () => {
const primaryEnvironmentId = EnvironmentId.make("environment-primary");

it("shows the picker for projects in the primary environment", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: primaryEnvironmentId,
primaryEnvironmentId,
remoteOpenMode: "local-exec",
}),
).toBe(true);
});

it("shows the picker for remote environments in deep-link mode", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
primaryEnvironmentId,
remoteOpenMode: "remote-links",
}),
).toBe(true);
});

it("shows the picker's unavailable state for remote environments without an SSH route", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
primaryEnvironmentId: null,
remoteOpenMode: "remote-unavailable",
}),
).toBe(true);
});

it("hides the picker for non-primary local backends", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: "codething-mvp",
activeThreadEnvironmentId: EnvironmentId.make("environment-remote"),
primaryEnvironmentId,
remoteOpenMode: "local-exec",
}),
).toBe(false);
});

it("hides the picker when there is no active project", () => {
expect(
shouldShowOpenInPicker({
activeProjectName: undefined,
activeThreadEnvironmentId: primaryEnvironmentId,
primaryEnvironmentId,
remoteOpenMode: "remote-links",
}),
).toBe(false);
});
});
import { resolveRenameCommit } from "./ChatHeader";

describe("resolveRenameCommit", () => {
it("commits a trimmed changed title", () => {
Expand Down
42 changes: 11 additions & 31 deletions apps/web/src/components/chat/ChatHeader.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import {
type EnvironmentId,
type EditorId,
type ProjectScript,
type ResolvedKeybindingsConfig,
type ThreadId,
Expand Down Expand Up @@ -32,8 +31,8 @@ import ProjectScriptsControl, {
type NewProjectScriptInput,
type ProjectScriptActionResult,
} from "../ProjectScriptsControl";
import { OpenInPicker } from "./OpenInPicker";
import { useRemoteOpenState, type RemoteOpenMode } from "../../remoteOpen";
import { OpenInPicker, shouldShowOpenInPicker } from "./OpenInPicker";
import { useIsDesktopLocalEnvironment, useRemoteOpenState } from "../../remoteOpen";
import { usePrimaryEnvironmentId } from "../../state/environments";
import { useT3ProjectFileScripts } from "~/hooks/useT3ProjectFileScripts";
import { useThreadActionMenu } from "~/hooks/useThreadActionMenu";
Expand Down Expand Up @@ -65,7 +64,6 @@ interface ChatHeaderProps {
activeProjectScripts: ReadonlyArray<ProjectScript> | undefined;
preferredScriptId: string | null;
keybindings: ResolvedKeybindingsConfig;
availableEditors: ReadonlyArray<EditorId>;
rightPanelOpen: boolean;
gitCwd: string | null;
readonly onOpenPullRequest?: ((number: number) => void) | undefined;
Expand Down Expand Up @@ -104,25 +102,6 @@ const TITLE_MENU_OPEN_DELAY_MS = 500;
// Matches the @3xl/header-actions container breakpoint owned by this header.
const HEADER_ACTIONS_EXPANDED_BREAKPOINT_REM = 48;

export function shouldShowOpenInPicker(input: {
readonly activeProjectName: string | undefined;
readonly activeThreadEnvironmentId: EnvironmentId;
readonly primaryEnvironmentId: EnvironmentId | null;
readonly remoteOpenMode: RemoteOpenMode;
}): boolean {
if (!input.activeProjectName) return false;
if (
input.primaryEnvironmentId !== null &&
input.activeThreadEnvironmentId === input.primaryEnvironmentId
) {
return true;
}
// Remote environments get the picker in deep-link mode (or its explicit
// "no SSH route" state). Non-primary local backends (e.g. WSL) keep it
// hidden, matching pre-remote behavior.
return input.remoteOpenMode !== "local-exec";
}

export const ChatHeader = memo(function ChatHeader({
activeThreadEnvironmentId,
activeThreadId,
Expand All @@ -134,7 +113,6 @@ export const ChatHeader = memo(function ChatHeader({
activeProjectScripts,
preferredScriptId,
keybindings,
availableEditors,
rightPanelOpen,
gitCwd,
onOpenPullRequest,
Expand Down Expand Up @@ -202,12 +180,15 @@ export const ChatHeader = memo(function ChatHeader({
activeProjectScripts ? activeProjectCwd : null,
);
const remoteOpenState = useRemoteOpenState(activeThreadEnvironmentId);
const showOpenInPicker = shouldShowOpenInPicker({
activeProjectName,
activeThreadEnvironmentId,
primaryEnvironmentId,
remoteOpenMode: remoteOpenState.mode,
});
const isDesktopLocalEnvironment = useIsDesktopLocalEnvironment(activeThreadEnvironmentId);
const showOpenInPicker =
Boolean(activeProjectName) &&
shouldShowOpenInPicker({
environmentId: activeThreadEnvironmentId,
primaryEnvironmentId,
isDesktopLocalEnvironment,
remoteOpenMode: remoteOpenState.mode,
});
const activeThreadRef = useMemo(
() => scopeThreadRef(activeThreadEnvironmentId, activeThreadId),
[activeThreadEnvironmentId, activeThreadId],
Expand Down Expand Up @@ -376,7 +357,6 @@ export const ChatHeader = memo(function ChatHeader({
presentation={actionsCollapsed ? "menu" : "toolbar"}
environmentId={activeThreadEnvironmentId}
keybindings={keybindings}
availableEditors={availableEditors}
openInCwd={openInCwd}
/>
</>
Expand Down
63 changes: 62 additions & 1 deletion apps/web/src/components/chat/OpenInPicker.test.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { EnvironmentId } from "@t3tools/contracts";
import { FolderClosedIcon } from "lucide-react";
import { describe, expect, it } from "vite-plus/test";

import { FileExplorerIcon, FinderIcon } from "../Icons";
import { resolveOpenInOptions } from "./OpenInPicker";
import { resolveOpenInOptions, shouldShowOpenInPicker } from "./OpenInPicker";

describe("resolveOpenInOptions", () => {
it.each([
Expand All @@ -24,3 +25,63 @@ describe("resolveOpenInOptions", () => {
expect(resolveOpenInOptions("MacIntel", [])).toEqual([]);
});
});

describe("shouldShowOpenInPicker", () => {
const primaryEnvironmentId = EnvironmentId.make("environment-primary");
const otherEnvironmentId = EnvironmentId.make("environment-other");

it("shows the picker for the primary environment", () => {
expect(
shouldShowOpenInPicker({
environmentId: primaryEnvironmentId,
primaryEnvironmentId,
isDesktopLocalEnvironment: false,
remoteOpenMode: "local-exec",
}),
).toBe(true);
});

it("shows the picker for desktop-local backends such as WSL", () => {
expect(
shouldShowOpenInPicker({
environmentId: otherEnvironmentId,
primaryEnvironmentId,
isDesktopLocalEnvironment: true,
remoteOpenMode: "local-exec",
}),
).toBe(true);
});

it("shows the picker for remote environments in deep-link mode", () => {
expect(
shouldShowOpenInPicker({
environmentId: otherEnvironmentId,
primaryEnvironmentId,
isDesktopLocalEnvironment: false,
remoteOpenMode: "remote-links",
}),
).toBe(true);
});

it("shows the picker when a remote environment has no SSH route", () => {
expect(
shouldShowOpenInPicker({
environmentId: otherEnvironmentId,
primaryEnvironmentId: null,
isDesktopLocalEnvironment: false,
remoteOpenMode: "remote-unavailable",
}),
).toBe(true);
});

it("hides the picker for an unclassified non-primary local-exec environment", () => {
expect(
shouldShowOpenInPicker({
environmentId: otherEnvironmentId,
primaryEnvironmentId,
isDesktopLocalEnvironment: false,
remoteOpenMode: "local-exec",
}),
).toBe(false);
});
});
Loading
Loading