[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

@@ -11,7 +11,6 @@ import {
loadSettings,
SettingScope,
type LoadedSettings,
type LoadableSettingScope,
} from '../../config/settings.js';
const emitConsoleLog = vi.hoisted(() => vi.fn());
@@ -58,8 +57,14 @@ describe('skills enable command', () => {
describe('handleEnable', () => {
it('should enable a disabled skill in user scope', async () => {
const mockSettings = {
forScope: vi.fn().mockReturnValue({
settings: { skills: { disabled: ['skill1'] } },
forScope: vi.fn().mockImplementation((scope) => {
if (scope === SettingScope.User) {
return {
settings: { skills: { disabled: ['skill1'] } },
path: '/user/settings.json',
};
}
return { settings: {}, path: '/project/settings.json' };
}),
setValue: vi.fn(),
};
@@ -67,10 +72,7 @@ describe('skills enable command', () => {
mockSettings as unknown as LoadedSettings,
);
await handleEnable({
name: 'skill1',
scope: SettingScope.User as LoadableSettingScope,
});
await handleEnable({ name: 'skill1' });
expect(mockSettings.setValue).toHaveBeenCalledWith(
SettingScope.User,
@@ -79,7 +81,48 @@ describe('skills enable command', () => {
);
expect(emitConsoleLog).toHaveBeenCalledWith(
'log',
'Skill "skill1" enabled by removing it from the disabled list in user settings.',
'Skill "skill1" enabled by removing it from the disabled list in user and project settings.',
);
});
it('should enable a skill across multiple scopes', async () => {
const mockSettings = {
forScope: vi.fn().mockImplementation((scope) => {
if (scope === SettingScope.User) {
return {
settings: { skills: { disabled: ['skill1'] } },
path: '/user/settings.json',
};
}
if (scope === SettingScope.Workspace) {
return {
settings: { skills: { disabled: ['skill1'] } },
path: '/workspace/settings.json',
};
}
return { settings: {}, path: '' };
}),
setValue: vi.fn(),
};
mockLoadSettings.mockReturnValue(
mockSettings as unknown as LoadedSettings,
);
await handleEnable({ name: 'skill1' });
expect(mockSettings.setValue).toHaveBeenCalledWith(
SettingScope.User,
'skills.disabled',
[],
);
expect(mockSettings.setValue).toHaveBeenCalledWith(
SettingScope.Workspace,
'skills.disabled',
[],
);
expect(emitConsoleLog).toHaveBeenCalledWith(
'log',
'Skill "skill1" enabled by removing it from the disabled list in project and user settings.',
);
});
@@ -91,11 +134,11 @@ describe('skills enable command', () => {
}),
setValue: vi.fn(),
};
vi.mocked(loadSettings).mockReturnValue(
mockLoadSettings.mockReturnValue(
mockSettings as unknown as LoadedSettings,
);
await handleEnable({ name: 'skill1', scope: SettingScope.User });
await handleEnable({ name: 'skill1' });
expect(mockSettings.setValue).not.toHaveBeenCalled();
expect(emitConsoleLog).toHaveBeenCalledWith(

View File

@@ -5,11 +5,7 @@
*/
import type { CommandModule } from 'yargs';
import {
loadSettings,
SettingScope,
type LoadableSettingScope,
} from '../../config/settings.js';
import { loadSettings } from '../../config/settings.js';
import { debugLogger } from '@google/gemini-cli-core';
import { exitCli } from '../utils.js';
import { enableSkill } from '../../utils/skillSettings.js';
@@ -17,15 +13,14 @@ import { renderSkillActionFeedback } from '../../utils/skillUtils.js';
interface EnableArgs {
name: string;
scope: LoadableSettingScope;
}
export async function handleEnable(args: EnableArgs) {
const { name, scope } = args;
const { name } = args;
const workspaceDir = process.cwd();
const settings = loadSettings(workspaceDir);
const result = enableSkill(settings, name, scope);
const result = enableSkill(settings, name);
debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label));
}
@@ -33,25 +28,14 @@ export const enableCommand: CommandModule = {
command: 'enable <name>',
describe: 'Enables an agent skill.',
builder: (yargs) =>
yargs
.positional('name', {
describe: 'The name of the skill to enable.',
type: 'string',
demandOption: true,
})
.option('scope', {
alias: 's',
describe: 'The scope to enable the skill in (user or project).',
type: 'string',
default: 'user',
choices: ['user', 'project'],
}),
yargs.positional('name', {
describe: 'The name of the skill to enable.',
type: 'string',
demandOption: true,
}),
handler: async (argv) => {
const scope: LoadableSettingScope =
argv['scope'] === 'project' ? SettingScope.Workspace : SettingScope.User;
await handleEnable({
name: argv['name'] as string,
scope,
});
await exitCli();
},