Skip to content
Merged
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
19 changes: 15 additions & 4 deletions src/components/FileBrowser.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,8 @@ import { Popover, PopoverContent, PopoverTrigger } from "./ui/popover";
import { Tabs, TabsList, TabsTrigger } from "./ui/tabs";
import { Textarea } from "./ui/textarea";
import { DirectoryBatchLoader } from "./file-browser/directoryBatchLoader";
import { REMOTE_FILE_TREE_REASON } from "../lib/remote-capabilities";
import { remoteRepositoryContaining } from "../lib/repository-adapter";
import { flattenExpandedTree } from "./file-browser/flattenTree";

// Helper to check if file is binary
Expand Down Expand Up @@ -1204,8 +1206,9 @@ export const FileBrowser = ({
})();

const workspacePath = workspace ? getFullWorkspacePath(workspace) : basePath;
const isRemoteTree = remoteRepositoryContaining(basePath) !== null;
useSWR(
repoPath
repoPath && !isRemoteTree
? [
"ensure-workspace-indexed",
repoPath,
Expand All @@ -1221,8 +1224,9 @@ export const FileBrowser = ({
data: loadedRootEntries,
isLoading: isLoadingDir,
mutate: mutateRootEntries,
} = useSWR(basePath ? ["list-directory", basePath] : null, async () =>
filterHiddenEntries(await listDirectory(basePath)),
} = useSWR(
basePath && !isRemoteTree ? ["list-directory", basePath] : null,
async () => filterHiddenEntries(await listDirectory(basePath)),
);
const rootEntries = loadedRootEntries ?? EMPTY_DIRECTORY_ENTRIES;

Expand Down Expand Up @@ -2016,7 +2020,14 @@ export const FileBrowser = ({
<div className="flex-1 flex min-h-0 overflow-hidden">
{/* File Tree */}
<div className="w-72 flex-shrink-0 border-r bg-sidebar overflow-hidden">
{isLoadingDir && rootEntries.length === 0 ? (
{isRemoteTree ? (
<p
className="p-4 text-sm text-muted-foreground"
data-testid="remote-file-tree-unavailable"
>
{REMOTE_FILE_TREE_REASON}
</p>
) : isLoadingDir && rootEntries.length === 0 ? (
<div className="flex items-center justify-center p-4">
<Loader2 className="w-6 h-6 animate-spin text-muted-foreground" />
</div>
Expand Down
13 changes: 10 additions & 3 deletions src/components/ShowWorkspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ import {
} from "../lib/commitsTabLabel";
import { cn, getFullWorkspacePath, resolveReadmeImageSrc } from "../lib/utils";
import { sumWorkspaceLocFromLog } from "../lib/workspace-stack";
import { REMOTE_FILE_TREE_REASON } from "../lib/remote-capabilities";
import { RemoteOperationUnsupportedError } from "../lib/repository-adapter";
import type { AgentReviewComment } from "../lib/api-types-review";
import type { SessionCreationInfo } from "../types/sessions";
import { ChangesDiffViewer } from "./ChangesDiffViewer";
Expand Down Expand Up @@ -476,8 +478,11 @@ export const ShowWorkspace = ({
]);
return { entries, readme };
} catch (error) {
console.error("Failed to load workspace overview:", error);
return { entries: [], readme: null as string | null };
const unavailable = error instanceof RemoteOperationUnsupportedError;
if (!unavailable) {
console.error("Failed to load workspace overview:", error);
}
return { entries: [], readme: null as string | null, unavailable };
}
},
);
Expand Down Expand Up @@ -1290,7 +1295,9 @@ export const ShowWorkspace = ({
})}
{!overviewPending && rootEntries.length === 0 && (
<div className="px-4 py-8 text-center text-sm text-muted-foreground">
No files found
{overviewData?.unavailable
? REMOTE_FILE_TREE_REASON
: "No files found"}
</div>
)}
</div>
Expand Down
42 changes: 29 additions & 13 deletions src/lib/api-extra.ts
Original file line number Diff line number Diff line change
Expand Up @@ -284,37 +284,53 @@ export const writeAgentCliFiles = (
export const cleanupAgentCliFiles = (paths: string[]): Promise<void> =>
invoke("cleanup_agent_cli_files", { paths });

export const getFileModifiedAt = (path: string): Promise<string | null> =>
invoke("get_file_modified_at", { path });
const FILE_TREE = "Browsing the file tree";

export const listDirectory = (path: string): Promise<DirectoryEntry[]> =>
invoke("list_directory", { path });
export const getFileModifiedAt = async (
path: string,
): Promise<string | null> => {
assertLocalOperation(path, FILE_TREE);
return invoke("get_file_modified_at", { path });
};

export const listDirectory = async (
path: string,
): Promise<DirectoryEntry[]> => {
assertLocalOperation(path, FILE_TREE);
return invoke("list_directory", { path });
};

export interface DirectoryBatchResult {
path: string;
entries: DirectoryEntry[];
error?: string;
}

export const listDirectoriesBatch = (
export const listDirectoriesBatch = async (
paths: string[],
): Promise<DirectoryBatchResult[]> =>
invoke("list_directories_batch", { paths });
): Promise<DirectoryBatchResult[]> => {
for (const path of paths) assertLocalOperation(path, FILE_TREE);
return invoke("list_directories_batch", { paths });
};

export const lsWorkspaceWithStatus = (
export const lsWorkspaceWithStatus = async (
repoPath: string,
workspaceId: number | null,
): Promise<DirectoryEntry[]> =>
invoke("ls_workspace_with_status", { repoPath, workspaceId });
): Promise<DirectoryEntry[]> => {
assertLocalOperation(repoPath, FILE_TREE);
return invoke("ls_workspace_with_status", { repoPath, workspaceId });
};

// Kept as the typed frontend counterpart of the registered Tauri command.
// eslint-disable-next-line local/no-unused-exported-ts-functions, local/require-tauri-api-exports-used
export const listDirectoryCached = (
export const listDirectoryCached = async (
repoPath: string,
workspaceId: number | null,
parentPath: string,
): Promise<CachedDirectoryEntry[]> =>
invoke("list_directory_cached", { repoPath, workspaceId, parentPath });
): Promise<CachedDirectoryEntry[]> => {
assertLocalOperation(repoPath, FILE_TREE);
return invoke("list_directory_cached", { repoPath, workspaceId, parentPath });
};

export interface SendArtifactRecord {
id: string;
Expand Down
16 changes: 10 additions & 6 deletions src/lib/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -124,16 +124,18 @@ export const archiveWorkspace = async (
});
};

export const ensureWorkspaceIndexed = (
export const ensureWorkspaceIndexed = async (
repoPath: string,
workspaceId: number | null,
workspacePath: string,
): Promise<boolean> =>
invoke("ensure_workspace_indexed", {
): Promise<boolean> => {
assertLocalOperation(repoPath, "Indexing workspace files");
return invoke("ensure_workspace_indexed", {
repoPath,
workspaceId,
workspacePath,
});
};

export const getSetting = (key: string): Promise<string | null> =>
invoke("get_setting", { key });
Expand Down Expand Up @@ -247,11 +249,13 @@ export const listGitignoredPathSuggestions = (
): Promise<string[]> =>
invoke("list_gitignored_path_suggestions", { repoPath });

export const getWorkspaceReadme = (
export const getWorkspaceReadme = async (
repoPath: string,
workspaceId: number | null,
): Promise<string | null> =>
invoke("get_workspace_readme", { repoPath, workspaceId });
): Promise<string | null> => {
assertLocalOperation(repoPath, "Reading the workspace README");
return invoke("get_workspace_readme", { repoPath, workspaceId });
};

export const getWorkspaceFileHunks = (
repoPath: string,
Expand Down
3 changes: 3 additions & 0 deletions src/lib/remote-capabilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
export const REMOTE_MERGE_REASON =
"Merging a remote workspace is not available yet. Push the branch and merge it from your hosting provider instead.";

export const REMOTE_FILE_TREE_REASON =
"Browsing the file tree is not available for remote repositories yet. Use Go to file to open a file.";

export interface ActionCapability {
supported: boolean;
reason?: string;
Expand Down
7 changes: 0 additions & 7 deletions src/lib/remote-path-guards.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,28 +25,22 @@ const NOT_REPOSITORY_PATHS = new Set(["cleanupAgentCliFiles"]);
const KNOWN_UNGUARDED: string[] = [
"apply_stash",
"delete_stash",
"ensure_workspace_indexed",
"export_stash_git_patch",
"get_cached_pr_ci_status",
"get_cached_pr_info",
"get_file_modified_at",
"get_git_remote_url",
"get_log_timeseries",
"get_pr_checks_via_gh",
"get_pr_info_via_gh",
"get_repo_logs",
"get_stash_diff",
"get_workspace_readme",
"get_workspace_setup_status",
"github_open_or_create_workspace_from_issue",
"init_repo",
"is_repo_trusted",
"jj_check_branch_exists",
"list_cached_pr_ci_statuses",
"list_cached_pr_statuses",
"list_directories_batch",
"list_directory",
"list_directory_cached",
"list_gitignored_path_suggestions",
"list_installed_skills",
"list_send_artifacts",
Expand All @@ -55,7 +49,6 @@ const KNOWN_UNGUARDED: string[] = [
"list_workflow_runs",
"list_workflows",
"load_repo_yaml_config",
"ls_workspace_with_status",
"open_or_create_workspace_from_pr",
"refresh_pr_branch_status",
"refresh_pr_statuses",
Expand Down
Loading