feat(filesystem): enhance agent filesystem API with searchSpaceId support for improved context handling

This commit is contained in:
Anish Sarkar 2026-04-27 21:00:40 +05:30
parent 86e2dc8a5d
commit 27e16231c1
10 changed files with 349 additions and 85 deletions

View file

@ -214,7 +214,7 @@ function AuthenticatedDocumentsSidebar({
if (!electronAPI?.getAgentFilesystemSettings) return;
let mounted = true;
electronAPI
.getAgentFilesystemSettings()
.getAgentFilesystemSettings(searchSpaceId)
.then((settings: FilesystemSettings) => {
if (!mounted) return;
setFilesystemSettings(settings);
@ -230,7 +230,7 @@ function AuthenticatedDocumentsSidebar({
return () => {
mounted = false;
};
}, [electronAPI]);
}, [electronAPI, searchSpaceId]);
const hasLocalFilesystemTrust = useCallback(() => {
try {
@ -253,10 +253,10 @@ function AuthenticatedDocumentsSidebar({
const updated = await electronAPI.setAgentFilesystemSettings({
mode: "desktop_local_folder",
localRootPaths: nextLocalRootPaths,
});
}, searchSpaceId);
setFilesystemSettings(updated);
},
[electronAPI, localRootPaths]
[electronAPI, localRootPaths, searchSpaceId]
);
const runPickLocalRoot = useCallback(async () => {
@ -285,10 +285,10 @@ function AuthenticatedDocumentsSidebar({
const updated = await electronAPI.setAgentFilesystemSettings({
mode: "desktop_local_folder",
localRootPaths: localRootPaths.filter((rootPath) => rootPath !== rootPathToRemove),
});
}, searchSpaceId);
setFilesystemSettings(updated);
},
[electronAPI, localRootPaths]
[electronAPI, localRootPaths, searchSpaceId]
);
const handleClearFilesystemRoots = useCallback(async () => {
@ -296,19 +296,19 @@ function AuthenticatedDocumentsSidebar({
const updated = await electronAPI.setAgentFilesystemSettings({
mode: "desktop_local_folder",
localRootPaths: [],
});
}, searchSpaceId);
setFilesystemSettings(updated);
}, [electronAPI]);
}, [electronAPI, searchSpaceId]);
const handleFilesystemTabChange = useCallback(
async (tab: "cloud" | "local") => {
if (!electronAPI?.setAgentFilesystemSettings) return;
const updated = await electronAPI.setAgentFilesystemSettings({
mode: tab === "cloud" ? "cloud" : "desktop_local_folder",
});
}, searchSpaceId);
setFilesystemSettings(updated);
},
[electronAPI]
[electronAPI, searchSpaceId]
);
// AI File Sort state
@ -1323,6 +1323,7 @@ function AuthenticatedDocumentsSidebar({
<LocalFilesystemBrowser
rootPaths={localRootPaths}
searchSpaceId={searchSpaceId}
active={currentFilesystemTab === "local"}
searchQuery={debouncedLocalSearch.trim() || undefined}
onOpenFile={(localFilePath) => {
openEditorPanel({

View file

@ -11,6 +11,7 @@ import { getSupportedExtensionsSet } from "@/lib/supported-extensions";
interface LocalFilesystemBrowserProps {
rootPaths: string[];
searchSpaceId: number;
active?: boolean;
searchQuery?: string;
onOpenFile: (fullPath: string) => void;
}
@ -75,6 +76,7 @@ function toMountedVirtualPath(mount: string, relativePath: string): string {
export function LocalFilesystemBrowser({
rootPaths,
searchSpaceId,
active = true,
searchQuery,
onOpenFile,
}: LocalFilesystemBrowserProps) {
@ -84,13 +86,36 @@ export function LocalFilesystemBrowser({
const [mountByRootKey, setMountByRootKey] = useState<Map<string, string>>(new Map());
const [mountStatus, setMountStatus] = useState<MountLoadStatus>("idle");
const [mountRefreshInFlight, setMountRefreshInFlight] = useState(false);
const lastLoadedRootsSignatureRef = useRef<string>("");
const hasLoadedMountsOnceRef = useRef(false);
const hasResolvedAtLeastOneRootRef = useRef(false);
const supportedExtensions = useMemo(() => Array.from(getSupportedExtensionsSet()), []);
const isWindowsPlatform = electronAPI?.versions.platform === "win32";
useEffect(() => {
if (!electronAPI?.listFolderFiles) return;
if (!active) return;
if (!electronAPI?.listAgentFilesystemFiles) {
for (const rootPath of rootPaths) {
setRootStateMap((prev) => ({
...prev,
[rootPath]: {
loading: false,
error: "Desktop app update required for local mode browsing.",
files: [],
},
}));
}
return;
}
const rootsSignature = rootPaths
.map((rootPath) => normalizeRootPathForLookup(rootPath, isWindowsPlatform))
.sort()
.join("|");
const settingsSignature = `${searchSpaceId}:${rootsSignature}`;
if (settingsSignature === lastLoadedRootsSignatureRef.current) {
return;
}
lastLoadedRootsSignatureRef.current = settingsSignature;
let cancelled = false;
for (const rootPath of rootPaths) {
@ -107,14 +132,11 @@ export function LocalFilesystemBrowser({
void Promise.all(
rootPaths.map(async (rootPath) => {
try {
const files = (await electronAPI.listFolderFiles({
path: rootPath,
name: getFolderDisplayName(rootPath),
const files = (await electronAPI.listAgentFilesystemFiles({
rootPath,
searchSpaceId,
excludePatterns: DEFAULT_EXCLUDE_PATTERNS,
fileExtensions: supportedExtensions,
rootFolderId: null,
searchSpaceId,
active: true,
})) as LocalFolderFileEntry[];
if (cancelled) return;
setRootStateMap((prev) => ({
@ -142,7 +164,7 @@ export function LocalFilesystemBrowser({
return () => {
cancelled = true;
};
}, [electronAPI, rootPaths, searchSpaceId, supportedExtensions]);
}, [active, electronAPI, isWindowsPlatform, rootPaths, searchSpaceId, supportedExtensions]);
useEffect(() => {
if (!electronAPI?.getAgentFilesystemMounts) {
@ -165,7 +187,7 @@ export function LocalFilesystemBrowser({
setMountRefreshInFlight(true);
}
void electronAPI
.getAgentFilesystemMounts()
.getAgentFilesystemMounts(searchSpaceId)
.then((mounts: LocalRootMount[]) => {
if (cancelled) return;
const next = new Map<string, string>();
@ -191,7 +213,7 @@ export function LocalFilesystemBrowser({
return () => {
cancelled = true;
};
}, [electronAPI, isWindowsPlatform, rootPaths]);
}, [electronAPI, isWindowsPlatform, rootPaths, searchSpaceId]);
const treeByRoot = useMemo(() => {
const query = searchQuery?.trim().toLowerCase() ?? "";