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
+6 -1
View File
@@ -1,3 +1,5 @@
import { createRealpathCache } from '../path-realpath-cache.js';
const EXEC_JOB_TTL_MS = 30 * 60 * 1000;
const createCommandTimeoutMs = () => {
@@ -270,6 +272,9 @@ export const registerFsRoutes = (app, dependencies) => {
resolveGitBinaryForSpawn,
openchamberUserConfigRoot,
} = dependencies;
const realpathCache = createRealpathCache({
realpath: fsPromises.realpath.bind(fsPromises),
});
const execJobs = new Map();
const commandTimeoutMs = createCommandTimeoutMs();
@@ -1033,7 +1038,7 @@ export const registerFsRoutes = (app, dependencies) => {
};
try {
resolvedPath = path.resolve(normalizeDirectoryPath(rawPath));
resolvedPath = await realpathCache.resolve(path.resolve(normalizeDirectoryPath(rawPath)));
const stats = await fsPromises.stat(resolvedPath);
if (!stats.isDirectory()) {