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.
This commit is contained in:
Bohdan Triapitsyn
2026-04-18 13:46:38 +03:00
parent 5710198864
commit 4901cf60b8
9 changed files with 753 additions and 147 deletions
+18
View File
@@ -0,0 +1,18 @@
export const createProjectIdFromPath = (projectPath: string): string => {
const normalized = projectPath.replace(/\\/g, '/').replace(/\/+$/g, '').trim();
if (!normalized) {
return '';
}
const data = new TextEncoder().encode(normalized);
let binary = '';
for (const byte of data) {
binary += String.fromCharCode(byte);
}
const encoded = typeof btoa === 'function'
? btoa(binary).replace(/\+/g, '-').replace(/\//g, '_').replace(/=+$/g, '')
: normalized.replace(/[^A-Za-z0-9._-]+/g, '_');
return `path_${encoded}`;
};