Repository navigation
feat(cli): support skill activation via /skill-name in non-interactive mode #29546
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
Hariharanpugazh
wants to merge
2
commits into
google-gemini:main
Choose a base branch
from
Hariharanpugazh:feat/skill-activation-non-interactive
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,160 @@ | ||
| /** | ||
| * @license | ||
| * Copyright 2025 Google LLC | ||
| * SPDX-License-Identifier: Apache-2.0 | ||
| */ | ||
|
|
||
| import { vi, describe, it, expect, beforeEach } from 'vitest'; | ||
| import { FatalInputError } from '@google/gemini-cli-core'; | ||
| import { handleSlashCommand } from './nonInteractiveCliCommands.js'; | ||
| import { CommandService } from './services/CommandService.js'; | ||
| import { CommandKind, type SlashCommand } from './ui/commands/types.js'; | ||
| import type { Config } from '@google/gemini-cli-core'; | ||
| import type { LoadedSettings } from './config/settings.js'; | ||
|
|
||
| vi.mock('./services/CommandService.js', () => ({ | ||
| CommandService: { | ||
| create: vi.fn(), | ||
| }, | ||
| })); | ||
| vi.mock('./ui/noninteractive/nonInteractiveUi.js', () => ({ | ||
| createNonInteractiveUI: vi.fn().mockReturnValue({}), | ||
| })); | ||
|
|
||
| function mockCommands(commands: SlashCommand[]) { | ||
| vi.mocked(CommandService.create).mockResolvedValue({ | ||
| getCommands: () => commands, | ||
| getConflicts: () => [], | ||
| } as unknown as CommandService); | ||
| } | ||
|
|
||
| describe('handleSlashCommand (non-interactive)', () => { | ||
| let mockConfig: Config; | ||
| let mockSettings: LoadedSettings; | ||
| let abortController: AbortController; | ||
|
|
||
| beforeEach(() => { | ||
| vi.clearAllMocks(); | ||
| abortController = new AbortController(); | ||
| // The loaders passed to CommandService.create are still constructed even | ||
| // though create() is mocked, so the config must expose the methods each | ||
| // loader touches in its constructor. | ||
| mockConfig = { | ||
| getSessionId: vi.fn().mockReturnValue('session-id'), | ||
| storage: {}, | ||
| getFolderTrust: vi.fn().mockReturnValue(false), | ||
| isTrustedFolder: vi.fn().mockReturnValue(true), | ||
| getProjectRoot: vi.fn().mockReturnValue('/project'), | ||
| getExtensions: vi.fn().mockReturnValue([]), | ||
| isSkillsSupportEnabled: vi.fn().mockReturnValue(false), | ||
| getSkillManager: vi.fn().mockReturnValue(null), | ||
| getPromptRegistry: vi.fn().mockReturnValue(undefined), | ||
| } as unknown as Config; | ||
| mockSettings = {} as unknown as LoadedSettings; | ||
| }); | ||
|
|
||
| it('returns undefined for input that is not a slash command', async () => { | ||
| mockCommands([]); | ||
| const result = await handleSlashCommand( | ||
| 'just a prompt', | ||
| abortController, | ||
| mockConfig, | ||
| mockSettings, | ||
| ); | ||
| expect(result).toBeUndefined(); | ||
| }); | ||
|
|
||
| it('returns the content for a submit_prompt action', async () => { | ||
| mockCommands([ | ||
| { | ||
| name: 'foo', | ||
| description: 'foo', | ||
| kind: CommandKind.BUILT_IN, | ||
| action: async () => ({ | ||
| type: 'submit_prompt', | ||
| content: 'hello model', | ||
| }), | ||
| }, | ||
| ]); | ||
|
|
||
| const result = await handleSlashCommand( | ||
| '/foo', | ||
| abortController, | ||
| mockConfig, | ||
| mockSettings, | ||
| ); | ||
| expect(result).toBe('hello model'); | ||
| }); | ||
|
|
||
| it('forwards postSubmitPrompt for a tool action (skill activation)', async () => { | ||
| mockCommands([ | ||
| { | ||
| name: 'my-skill', | ||
| description: 'Activate the my-skill skill', | ||
| kind: CommandKind.SKILL, | ||
| autoExecute: true, | ||
| action: async () => ({ | ||
| type: 'tool', | ||
| toolName: 'activate_skill', | ||
| toolArgs: { name: 'my-skill' }, | ||
| postSubmitPrompt: 'Use the skill my-skill', | ||
| }), | ||
| }, | ||
| ]); | ||
|
|
||
| const result = await handleSlashCommand( | ||
| '/my-skill', | ||
| abortController, | ||
| mockConfig, | ||
| mockSettings, | ||
| ); | ||
| expect(result).toBe('Use the skill my-skill'); | ||
| }); | ||
|
|
||
| it('throws for a tool action without a postSubmitPrompt', async () => { | ||
| mockCommands([ | ||
| { | ||
| name: 'bare-tool', | ||
| description: 'bare', | ||
| kind: CommandKind.SKILL, | ||
| action: async () => ({ | ||
| type: 'tool', | ||
| toolName: 'activate_skill', | ||
| toolArgs: { name: 'bare' }, | ||
| }), | ||
| }, | ||
| ]); | ||
|
|
||
| await expect( | ||
| handleSlashCommand( | ||
| '/bare-tool', | ||
| abortController, | ||
| mockConfig, | ||
| mockSettings, | ||
| ), | ||
| ).rejects.toThrow(FatalInputError); | ||
| }); | ||
|
|
||
| it('throws for a confirm_shell_commands action', async () => { | ||
| mockCommands([ | ||
| { | ||
| name: 'needs-confirm', | ||
| description: 'confirm', | ||
| kind: CommandKind.BUILT_IN, | ||
| action: async () => ({ | ||
| type: 'confirm_shell_commands', | ||
| commandsToConfirm: ['rm -rf /'], | ||
| }), | ||
| }, | ||
| ] as unknown as SlashCommand[]); | ||
|
|
||
| await expect( | ||
| handleSlashCommand( | ||
| '/needs-confirm', | ||
| abortController, | ||
| mockConfig, | ||
| mockSettings, | ||
| ), | ||
| ).rejects.toThrow(FatalInputError); | ||
| }); | ||
| }); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When a command resolves to a
toolaction in non-interactive mode, it cannot schedule a UI tool call. Therefore, it must rely on apostSubmitPromptto forward the request to the model. IfpostSubmitPromptis missing or undefined, the command cannot be executed and will silently fail (returningundefined).Following the general rule to handle
undefinedcases for optional properties and avoid relying on implementation details of specific loaders, we should explicitly throw aFatalInputErrorifpostSubmitPromptis not provided, consistent with how other unsupported actions are handled in non-interactive mode.References