Files
openchamber/packages/web/server/lib/projects/project-id.js
T
Bohdan Triapitsyn 4901cf60b8 fix(projects): deterministic project identity + safe per-project persistence
Derive project.id from project.path (path_<base64url(path)>), shared helper on
both server (lib/projects/project-id.js) and client (lib/projectId.ts). Replace
random UUIDs so icons, notes, todos, actions, setup-worktree, plans and
scheduledTasks share one id across restarts and reinstalls.

Fix read-then-overwrite clobber in project-config.js: scheduled-task writes now
merge with the existing project json instead of replacing it, preserving
client-written fields that live in the same file.

On settings load migrate legacy UUID ids to canonical path ids, moving config
json, storage dir contents and icon files, and remap activeProjectId. Scan for
orphan non-path_* project configs and merge them into the canonical project
when a \$ROOT_PROJECT_PATH/<file> reference resolves on disk, logging any that
can't be matched.

Client openchamberConfig.writeOpenChamberConfig re-asserts server-owned keys
(version, scheduledTasks) on write to defeat the symmetric race. Stores and
persistence derive ids from path consistently.
2026-04-18 13:46:38 +03:00

14 lines
405 B
JavaScript

const normalizeProjectPathForId = (value) => {
if (typeof value !== 'string') return '';
return value.replace(/\\/g, '/').replace(/\/+$/g, '') || value;
};
export const createProjectIdFromPath = (projectPath) => {
const normalized = normalizeProjectPathForId(projectPath).trim();
if (!normalized) {
return '';
}
return `path_${Buffer.from(normalized, 'utf8').toString('base64url')}`;
};