mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-25 20:44:46 -07:00
feat(admin): support admin-enforced settings for Agent Skills (#16406)
This commit is contained in:
@@ -2091,5 +2091,30 @@ describe('Config JIT Initialization', () => {
|
||||
|
||||
expect(skillManager.setDisabledSkills).toHaveBeenCalledWith([]);
|
||||
});
|
||||
|
||||
it('should update admin settings from onReload', async () => {
|
||||
const mockOnReload = vi.fn().mockResolvedValue({
|
||||
adminSkillsEnabled: false,
|
||||
});
|
||||
const params: ConfigParameters = {
|
||||
sessionId: 'test-session',
|
||||
targetDir: '/tmp/test',
|
||||
debugMode: false,
|
||||
model: 'test-model',
|
||||
cwd: '/tmp/test',
|
||||
skillsSupport: true,
|
||||
onReload: mockOnReload,
|
||||
};
|
||||
|
||||
config = new Config(params);
|
||||
await config.initialize();
|
||||
|
||||
const skillManager = config.getSkillManager();
|
||||
vi.spyOn(skillManager, 'setAdminSettings');
|
||||
|
||||
await config.reloadSkills();
|
||||
|
||||
expect(skillManager.setAdminSettings).toHaveBeenCalledWith(false);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -377,13 +377,17 @@ export interface ConfigParameters {
|
||||
enableAgents?: boolean;
|
||||
skillsSupport?: boolean;
|
||||
disabledSkills?: string[];
|
||||
adminSkillsEnabled?: boolean;
|
||||
experimentalJitContext?: boolean;
|
||||
disableLLMCorrection?: boolean;
|
||||
onModelChange?: (model: string) => void;
|
||||
mcpEnabled?: boolean;
|
||||
extensionsEnabled?: boolean;
|
||||
agents?: AgentSettings;
|
||||
onReload?: () => Promise<{ disabledSkills?: string[] }>;
|
||||
onReload?: () => Promise<{
|
||||
disabledSkills?: string[];
|
||||
adminSkillsEnabled?: boolean;
|
||||
}>;
|
||||
}
|
||||
|
||||
export class Config {
|
||||
@@ -511,13 +515,17 @@ export class Config {
|
||||
private hookSystem?: HookSystem;
|
||||
private readonly onModelChange: ((model: string) => void) | undefined;
|
||||
private readonly onReload:
|
||||
| (() => Promise<{ disabledSkills?: string[] }>)
|
||||
| (() => Promise<{
|
||||
disabledSkills?: string[];
|
||||
adminSkillsEnabled?: boolean;
|
||||
}>)
|
||||
| undefined;
|
||||
|
||||
private readonly enableAgents: boolean;
|
||||
private readonly agents: AgentSettings;
|
||||
private readonly skillsSupport: boolean;
|
||||
private disabledSkills: string[];
|
||||
private readonly adminSkillsEnabled: boolean;
|
||||
|
||||
private readonly experimentalJitContext: boolean;
|
||||
private readonly disableLLMCorrection: boolean;
|
||||
@@ -594,6 +602,7 @@ export class Config {
|
||||
this.disableLLMCorrection = params.disableLLMCorrection ?? false;
|
||||
this.skillsSupport = params.skillsSupport ?? false;
|
||||
this.disabledSkills = params.disabledSkills ?? [];
|
||||
this.adminSkillsEnabled = params.adminSkillsEnabled ?? true;
|
||||
this.modelAvailabilityService = new ModelAvailabilityService();
|
||||
this.previewFeatures = params.previewFeatures ?? undefined;
|
||||
this.experimentalJitContext = params.experimentalJitContext ?? false;
|
||||
@@ -777,20 +786,22 @@ export class Config {
|
||||
]);
|
||||
initMcpHandle?.end();
|
||||
|
||||
// Discover skills if enabled
|
||||
if (this.skillsSupport) {
|
||||
await this.getSkillManager().discoverSkills(
|
||||
this.storage,
|
||||
this.getExtensions(),
|
||||
);
|
||||
this.getSkillManager().setDisabledSkills(this.disabledSkills);
|
||||
|
||||
// Re-register ActivateSkillTool to update its schema with the discovered enabled skill enums
|
||||
if (this.getSkillManager().getSkills().length > 0) {
|
||||
this.getToolRegistry().unregisterTool(ActivateSkillTool.Name);
|
||||
this.getToolRegistry().registerTool(
|
||||
new ActivateSkillTool(this, this.messageBus),
|
||||
this.getSkillManager().setAdminSettings(this.adminSkillsEnabled);
|
||||
if (this.adminSkillsEnabled) {
|
||||
await this.getSkillManager().discoverSkills(
|
||||
this.storage,
|
||||
this.getExtensions(),
|
||||
);
|
||||
this.getSkillManager().setDisabledSkills(this.disabledSkills);
|
||||
|
||||
// Re-register ActivateSkillTool to update its schema with the discovered enabled skill enums
|
||||
if (this.getSkillManager().getSkills().length > 0) {
|
||||
this.getToolRegistry().unregisterTool(ActivateSkillTool.Name);
|
||||
this.getToolRegistry().registerTool(
|
||||
new ActivateSkillTool(this, this.messageBus),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1593,21 +1604,29 @@ export class Config {
|
||||
if (this.onReload) {
|
||||
const refreshed = await this.onReload();
|
||||
this.disabledSkills = refreshed.disabledSkills ?? [];
|
||||
this.getSkillManager().setAdminSettings(
|
||||
refreshed.adminSkillsEnabled ?? this.adminSkillsEnabled,
|
||||
);
|
||||
}
|
||||
|
||||
await this.getSkillManager().discoverSkills(
|
||||
this.storage,
|
||||
this.getExtensions(),
|
||||
);
|
||||
this.getSkillManager().setDisabledSkills(this.disabledSkills);
|
||||
|
||||
// Re-register ActivateSkillTool to update its schema with the newly discovered skills
|
||||
if (this.getSkillManager().getSkills().length > 0) {
|
||||
this.getToolRegistry().unregisterTool(ActivateSkillTool.Name);
|
||||
this.getToolRegistry().registerTool(
|
||||
new ActivateSkillTool(this, this.messageBus),
|
||||
if (this.getSkillManager().isAdminEnabled()) {
|
||||
await this.getSkillManager().discoverSkills(
|
||||
this.storage,
|
||||
this.getExtensions(),
|
||||
);
|
||||
this.getSkillManager().setDisabledSkills(this.disabledSkills);
|
||||
|
||||
// Re-register ActivateSkillTool to update its schema with the newly discovered skills
|
||||
if (this.getSkillManager().getSkills().length > 0) {
|
||||
this.getToolRegistry().unregisterTool(ActivateSkillTool.Name);
|
||||
this.getToolRegistry().registerTool(
|
||||
new ActivateSkillTool(this, this.messageBus),
|
||||
);
|
||||
} else {
|
||||
this.getToolRegistry().unregisterTool(ActivateSkillTool.Name);
|
||||
}
|
||||
} else {
|
||||
this.getSkillManager().clearSkills();
|
||||
this.getToolRegistry().unregisterTool(ActivateSkillTool.Name);
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user