[Skills] Multi-scope skill enablement and shadowing fix (#15953)

This commit is contained in:
N. Taylor Mullen
2026-01-06 20:24:29 -08:00
committed by GitHub
parent 7956eb239e
commit 2d683bb6f8
5 changed files with 154 additions and 64 deletions

View File

@@ -5,8 +5,8 @@
*/
import {
SettingScope,
isLoadableSettingScope,
type SettingScope,
type LoadedSettings,
} from '../config/settings.js';
@@ -33,47 +33,57 @@ export interface SkillActionResult {
}
/**
* Enables a skill by removing it from the specified disabled list.
* Enables a skill by removing it from all writable disabled lists (User and Workspace).
*/
export function enableSkill(
settings: LoadedSettings,
skillName: string,
scope: SettingScope,
): SkillActionResult {
if (!isLoadableSettingScope(scope)) {
return {
status: 'error',
skillName,
action: 'enable',
modifiedScopes: [],
alreadyInStateScopes: [],
error: `Invalid settings scope: ${scope}`,
};
const writableScopes = [SettingScope.Workspace, SettingScope.User];
const foundInDisabledScopes: ModifiedScope[] = [];
const alreadyEnabledScopes: ModifiedScope[] = [];
for (const scope of writableScopes) {
if (isLoadableSettingScope(scope)) {
const scopePath = settings.forScope(scope).path;
const scopeDisabled = settings.forScope(scope).settings.skills?.disabled;
if (scopeDisabled?.includes(skillName)) {
foundInDisabledScopes.push({ scope, path: scopePath });
} else {
alreadyEnabledScopes.push({ scope, path: scopePath });
}
}
}
const scopePath = settings.forScope(scope).path;
const currentScopeDisabled =
settings.forScope(scope).settings.skills?.disabled ?? [];
if (!currentScopeDisabled.includes(skillName)) {
if (foundInDisabledScopes.length === 0) {
return {
status: 'no-op',
skillName,
action: 'enable',
modifiedScopes: [],
alreadyInStateScopes: [{ scope, path: scopePath }],
alreadyInStateScopes: alreadyEnabledScopes,
};
}
const newDisabled = currentScopeDisabled.filter((name) => name !== skillName);
settings.setValue(scope, 'skills.disabled', newDisabled);
const modifiedScopes: ModifiedScope[] = [];
for (const { scope, path } of foundInDisabledScopes) {
if (isLoadableSettingScope(scope)) {
const currentScopeDisabled =
settings.forScope(scope).settings.skills?.disabled ?? [];
const newDisabled = currentScopeDisabled.filter(
(name) => name !== skillName,
);
settings.setValue(scope, 'skills.disabled', newDisabled);
modifiedScopes.push({ scope, path });
}
}
return {
status: 'success',
skillName,
action: 'enable',
modifiedScopes: [{ scope, path: scopePath }],
alreadyInStateScopes: [],
modifiedScopes,
alreadyInStateScopes: alreadyEnabledScopes,
};
}
@@ -110,6 +120,24 @@ export function disableSkill(
};
}
// Check if it's already disabled in the other writable scope
const otherScope =
scope === SettingScope.Workspace
? SettingScope.User
: SettingScope.Workspace;
const alreadyDisabledInOther: ModifiedScope[] = [];
if (isLoadableSettingScope(otherScope)) {
const otherScopeDisabled =
settings.forScope(otherScope).settings.skills?.disabled;
if (otherScopeDisabled?.includes(skillName)) {
alreadyDisabledInOther.push({
scope: otherScope,
path: settings.forScope(otherScope).path,
});
}
}
const newDisabled = [...currentScopeDisabled, skillName];
settings.setValue(scope, 'skills.disabled', newDisabled);
@@ -118,6 +146,6 @@ export function disableSkill(
skillName,
action: 'disable',
modifiedScopes: [{ scope, path: scopePath }],
alreadyInStateScopes: [],
alreadyInStateScopes: alreadyDisabledInOther,
};
}