mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-27 13:34:15 -07:00
[Skills] Foundation: Centralize management logic and feedback rendering (#15952)
This commit is contained in:
@@ -36,6 +36,7 @@ vi.mock('../../config/settings.js', async (importOriginal) => {
|
||||
return {
|
||||
...actual,
|
||||
loadSettings: vi.fn(),
|
||||
isLoadableSettingScope: vi.fn((s) => s === 'User' || s === 'Workspace'),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -78,7 +79,7 @@ describe('skills disable command', () => {
|
||||
);
|
||||
expect(emitConsoleLog).toHaveBeenCalledWith(
|
||||
'log',
|
||||
'Skill "skill1" successfully disabled in scope "User".',
|
||||
'Skill "skill1" disabled by adding it to the disabled list in user settings.',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -86,22 +87,20 @@ describe('skills disable command', () => {
|
||||
const mockSettings = {
|
||||
forScope: vi.fn().mockReturnValue({
|
||||
settings: { skills: { disabled: ['skill1'] } },
|
||||
path: '/user/settings.json',
|
||||
}),
|
||||
setValue: vi.fn(),
|
||||
};
|
||||
mockLoadSettings.mockReturnValue(
|
||||
vi.mocked(loadSettings).mockReturnValue(
|
||||
mockSettings as unknown as LoadedSettings,
|
||||
);
|
||||
|
||||
await handleDisable({
|
||||
name: 'skill1',
|
||||
scope: SettingScope.User as LoadableSettingScope,
|
||||
});
|
||||
await handleDisable({ name: 'skill1', scope: SettingScope.User });
|
||||
|
||||
expect(mockSettings.setValue).not.toHaveBeenCalled();
|
||||
expect(emitConsoleLog).toHaveBeenCalledWith(
|
||||
'log',
|
||||
'Skill "skill1" is already disabled in scope "User".',
|
||||
'Skill "skill1" is already disabled.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
} from '../../config/settings.js';
|
||||
import { debugLogger } from '@google/gemini-cli-core';
|
||||
import { exitCli } from '../utils.js';
|
||||
import { disableSkill } from '../../utils/skillSettings.js';
|
||||
import { renderSkillActionFeedback } from '../../utils/skillUtils.js';
|
||||
|
||||
interface DisableArgs {
|
||||
name: string;
|
||||
@@ -23,17 +25,8 @@ export async function handleDisable(args: DisableArgs) {
|
||||
const workspaceDir = process.cwd();
|
||||
const settings = loadSettings(workspaceDir);
|
||||
|
||||
const currentDisabled =
|
||||
settings.forScope(scope).settings.skills?.disabled || [];
|
||||
|
||||
if (currentDisabled.includes(name)) {
|
||||
debugLogger.log(`Skill "${name}" is already disabled in scope "${scope}".`);
|
||||
return;
|
||||
}
|
||||
|
||||
const newDisabled = [...currentDisabled, name];
|
||||
settings.setValue(scope, 'skills.disabled', newDisabled);
|
||||
debugLogger.log(`Skill "${name}" successfully disabled in scope "${scope}".`);
|
||||
const result = disableSkill(settings, name, scope);
|
||||
debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label));
|
||||
}
|
||||
|
||||
export const disableCommand: CommandModule = {
|
||||
|
||||
@@ -36,6 +36,7 @@ vi.mock('../../config/settings.js', async (importOriginal) => {
|
||||
return {
|
||||
...actual,
|
||||
loadSettings: vi.fn(),
|
||||
isLoadableSettingScope: vi.fn((s) => s === 'User' || s === 'Workspace'),
|
||||
};
|
||||
});
|
||||
|
||||
@@ -78,7 +79,7 @@ describe('skills enable command', () => {
|
||||
);
|
||||
expect(emitConsoleLog).toHaveBeenCalledWith(
|
||||
'log',
|
||||
'Skill "skill1" successfully enabled in scope "User".',
|
||||
'Skill "skill1" enabled by removing it from the disabled list in user settings.',
|
||||
);
|
||||
});
|
||||
|
||||
@@ -86,22 +87,20 @@ describe('skills enable command', () => {
|
||||
const mockSettings = {
|
||||
forScope: vi.fn().mockReturnValue({
|
||||
settings: { skills: { disabled: [] } },
|
||||
path: '/user/settings.json',
|
||||
}),
|
||||
setValue: vi.fn(),
|
||||
};
|
||||
mockLoadSettings.mockReturnValue(
|
||||
vi.mocked(loadSettings).mockReturnValue(
|
||||
mockSettings as unknown as LoadedSettings,
|
||||
);
|
||||
|
||||
await handleEnable({
|
||||
name: 'skill1',
|
||||
scope: SettingScope.User as LoadableSettingScope,
|
||||
});
|
||||
await handleEnable({ name: 'skill1', scope: SettingScope.User });
|
||||
|
||||
expect(mockSettings.setValue).not.toHaveBeenCalled();
|
||||
expect(emitConsoleLog).toHaveBeenCalledWith(
|
||||
'log',
|
||||
'Skill "skill1" is already enabled in scope "User".',
|
||||
'Skill "skill1" is already enabled.',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -12,6 +12,8 @@ import {
|
||||
} from '../../config/settings.js';
|
||||
import { debugLogger } from '@google/gemini-cli-core';
|
||||
import { exitCli } from '../utils.js';
|
||||
import { enableSkill } from '../../utils/skillSettings.js';
|
||||
import { renderSkillActionFeedback } from '../../utils/skillUtils.js';
|
||||
|
||||
interface EnableArgs {
|
||||
name: string;
|
||||
@@ -23,17 +25,8 @@ export async function handleEnable(args: EnableArgs) {
|
||||
const workspaceDir = process.cwd();
|
||||
const settings = loadSettings(workspaceDir);
|
||||
|
||||
const currentDisabled =
|
||||
settings.forScope(scope).settings.skills?.disabled || [];
|
||||
const newDisabled = currentDisabled.filter((d) => d !== name);
|
||||
|
||||
if (currentDisabled.length === newDisabled.length) {
|
||||
debugLogger.log(`Skill "${name}" is already enabled in scope "${scope}".`);
|
||||
return;
|
||||
}
|
||||
|
||||
settings.setValue(scope, 'skills.disabled', newDisabled);
|
||||
debugLogger.log(`Skill "${name}" successfully enabled in scope "${scope}".`);
|
||||
const result = enableSkill(settings, name, scope);
|
||||
debugLogger.log(renderSkillActionFeedback(result, (label, _path) => label));
|
||||
}
|
||||
|
||||
export const enableCommand: CommandModule = {
|
||||
|
||||
Reference in New Issue
Block a user