fix(skills): improve robustness of enable/disable operations

- Add rollback in moveDirectory when rmSync fails after cpSync
- Add transaction rollback in disable/enableSkill when config save fails
- Surface config corruption by throwing on JSON parse errors
- Add robust JSON error parsing with fallback in frontend
- Add loading state and double-click prevention for toggle button
This commit is contained in:
catlog22
2026-01-28 08:25:59 +08:00
parent af05874510
commit cc5a5716cf
2 changed files with 54 additions and 16 deletions

View File

@@ -64,19 +64,28 @@ function getDisabledSkillsConfigPath(location: SkillLocation, projectPath: strin
/**
* Load disabled skills configuration
* Throws on JSON parse errors to surface config corruption
*/
function loadDisabledSkillsConfig(location: SkillLocation, projectPath: string): DisabledSkillsConfig {
const configPath = getDisabledSkillsConfigPath(location, projectPath);
try {
if (existsSync(configPath)) {
const content = readFileSync(configPath, 'utf8');
const config = JSON.parse(content);
return { skills: config.skills || {} };
}
} catch (error) {
console.error(`[Skills] Failed to load disabled skills config: ${error}`);
if (!existsSync(configPath)) {
return { skills: {} };
}
try {
const content = readFileSync(configPath, 'utf8');
const config = JSON.parse(content);
return { skills: config.skills || {} };
} catch (error) {
// Throw on JSON parse errors to surface config corruption
if (error instanceof SyntaxError) {
throw new Error(`Config file corrupted: ${configPath}`);
}
// Log and return empty for other errors (permission, etc.)
console.error(`[Skills] Failed to load disabled skills config: ${error}`);
return { skills: {} };
}
return { skills: {} };
}
/**