feat(filesystem): introduce support for local openable text file extensions and enhance folder expansion persistence in the UI

This commit is contained in:
Anish Sarkar 2026-04-28 01:12:15 +05:30
parent 7134b0feae
commit b85b7cbae0
5 changed files with 202 additions and 28 deletions

View file

@ -21,6 +21,51 @@ const MAX_LOCAL_ROOTS = 10;
const DEFAULT_SPACE_KEY = "default";
let cachedSettingsStore: AgentFilesystemSettingsStore | null = null;
const LOCAL_OPENABLE_TEXT_EXTENSIONS = new Set<string>([
".md",
".markdown",
".txt",
".json",
".yaml",
".yml",
".csv",
".tsv",
".xml",
".html",
".htm",
".css",
".scss",
".sass",
".sql",
".toml",
".ini",
".conf",
".log",
".py",
".js",
".jsx",
".mjs",
".cjs",
".ts",
".tsx",
".java",
".kt",
".kts",
".go",
".rs",
".rb",
".php",
".swift",
".r",
".lua",
".sh",
".bash",
".zsh",
".fish",
".env",
".mk",
]);
function getSettingsPath(): string {
return join(app.getPath("userData"), SETTINGS_FILENAME);
}
@ -229,6 +274,16 @@ function toVirtualPath(rootPath: string, absolutePath: string): string {
return `/${rel.replace(/\\/g, "/")}`;
}
function assertLocalOpenableTextFile(absolutePath: string): void {
const extension = extname(absolutePath).toLowerCase();
if (!LOCAL_OPENABLE_TEXT_EXTENSIONS.has(extension)) {
throw new Error(
`Unsupported local file type '${extension || "(no extension)"}'. ` +
"Only text/code files can be opened in local mode."
);
}
}
export type LocalRootMount = {
mount: string;
rootPath: string;
@ -441,6 +496,7 @@ export async function readAgentLocalFileText(
);
}
const absolutePath = resolveVirtualPath(rootMount.rootPath, subPath);
assertLocalOpenableTextFile(absolutePath);
const content = await readFile(absolutePath, "utf8");
return {
path: toMountedVirtualPath(rootMount.mount, rootMount.rootPath, absolutePath),