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.
19 lines
552 B
TypeScript
19 lines
552 B
TypeScript
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}`;
|
|
};
|