mirror of
https://github.com/QwenLM/qwen-code.git
synced 2026-05-05 07:10:55 +00:00
refactor(settings): sequential settings migration
This commit is contained in:
parent
ac5a0c68e5
commit
ae8c0d3d4e
18 changed files with 3527 additions and 944 deletions
|
|
@ -7,7 +7,7 @@
|
|||
import * as path from 'node:path';
|
||||
import * as os from 'node:os';
|
||||
import * as fs from 'node:fs';
|
||||
import { getProjectHash } from '../utils/paths.js';
|
||||
import { getProjectHash, sanitizeCwd } from '../utils/paths.js';
|
||||
|
||||
export const QWEN_DIR = '.qwen';
|
||||
export const GOOGLE_ACCOUNTS_FILENAME = 'google_accounts.json';
|
||||
|
|
@ -82,7 +82,7 @@ export class Storage {
|
|||
}
|
||||
|
||||
getProjectDir(): string {
|
||||
const projectId = this.sanitizeCwd(this.getProjectRoot());
|
||||
const projectId = sanitizeCwd(this.getProjectRoot());
|
||||
const projectsDir = path.join(Storage.getGlobalQwenDir(), PROJECT_DIR_NAME);
|
||||
return path.join(projectsDir, projectId);
|
||||
}
|
||||
|
|
@ -140,10 +140,4 @@ export class Storage {
|
|||
getHistoryFilePath(): string {
|
||||
return path.join(this.getProjectTempDir(), 'shell_history');
|
||||
}
|
||||
|
||||
private 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, '-');
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue