fix: resolve symlinks in project directory paths (#1316)

* fix: resolve symlinks in project directory paths

OpenCode stores sessions using the canonical (realpath) directory, but
OpenChamber passed the unresolved symlink path in several places. The
string-match directory filter would fail when a project was accessed via
a symlink, making sessions invisible.

Changes:

- Add safeRealpathSync to settings normalization — project paths and
  lastDirectory are canonicalized at persistence time
- Add Express middleware before the API proxy to resolve symlinks in
  ?directory= query params on in-flight requests
- Resolve symlinks in /api/fs/list so the directory browser returns
  canonical paths, allowing the "already added" check to work correctly
- Reconcile the in-memory projects store when the server responds with
  normalized paths, preventing temporary duplicates

Fixes #1315

* fix: avoid sync realpath in opencode proxy

---------

Co-authored-by: Bohdan Triapitsyn <artmore@protonmail.com>
This commit is contained in:
jeremysamuel13
2026-05-24 15:46:11 +03:00
committed by GitHub
co-authored by Bohdan Triapitsyn
parent 90b3d4760e
commit c5862cc6ee
12 changed files with 695 additions and 12 deletions
@@ -42,6 +42,18 @@ interface DirectoryTreeProps {
disabledPaths?: Iterable<string>;
}
const areStringSetsEqual = (left: Set<string>, right: Set<string>) => {
if (left.size !== right.size) {
return false;
}
for (const value of left) {
if (!right.has(value)) {
return false;
}
}
return true;
};
export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
currentPath,
onSelectPath,
@@ -244,7 +256,10 @@ export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
const normalizedPath = path.replace(/\\/g, '/');
return (stripTrailingSlashes(normalizedPath) as string) ?? normalizedPath;
});
setPinnedPaths(new Set(normalized));
setPinnedPaths((prev) => {
const next = new Set(normalized);
return areStringSetsEqual(prev, next) ? prev : next;
});
};
const loadFromLocalStorage = () => {
@@ -326,7 +341,8 @@ export const DirectoryTree: React.FC<DirectoryTreeProps> = ({
const filtered = Array.from(prev)
.map((path) => (stripTrailingSlashes(path.replace(/\\/g, '/')) as string) ?? path)
.filter((path) => isPathWithinHome(path));
return new Set(filtered);
const next = new Set(filtered);
return areStringSetsEqual(prev, next) ? prev : next;
});
}, [effectiveRoot, isPathWithinHome, stripTrailingSlashes]);