refactor(settings): sequential settings migration

This commit is contained in:
mingholy.lmh 2026-02-28 18:13:25 +08:00
parent ac5a0c68e5
commit ae8c0d3d4e
18 changed files with 3527 additions and 944 deletions

View file

@ -202,6 +202,25 @@ export function getProjectHash(projectRoot: string): string {
return crypto.createHash('sha256').update(normalizedPath).digest('hex');
}
/**
* Sanitizes a directory path to create a safe project ID.
*
* - On Windows: normalizes to lowercase for case-insensitive matching
* - Replaces all non-alphanumeric characters with hyphens
*
* This is used for:
* - Creating project-specific directories
* - Generating session IDs for debug logging during startup
*
* @param cwd - The directory path to sanitize
* @returns A sanitized string safe for use as a project identifier
*/
export function sanitizeCwd(cwd: string): string {
// On Windows, normalize to lowercase for case-insensitive matching
const normalizedCwd = os.platform() === 'win32' ? cwd.toLowerCase() : cwd;
return normalizedCwd.replace(/[^a-zA-Z0-9]/g, '-');
}
/**
* Checks if a path is a subpath of another path.
* @param parentPath The parent path.