chore: clean up

This commit is contained in:
Spencer
2026-03-19 05:04:11 +00:00
parent 822e098d32
commit bf6804d9ed
18 changed files with 110 additions and 76 deletions
@@ -1,7 +1,7 @@
# Example Policy Rules for Gemini CLI Extension
#
# Extensions run in Tier 2 (Extension Tier).
# Security Note: 'allow' decisions and 'yolo' mode configurations are ignored.
# Security Note: 'allow' decisions and wildcard policies are ignored.
# Rule: Always ask the user before running a specific dangerous shell command.
[[rule]]
+45 -16
View File
@@ -158,7 +158,7 @@ vi.mock('@google/gemini-cli-core', async () => {
),
getAdminErrorMessage: vi.fn(
(_feature) =>
`YOLO mode is disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli`,
`Wildcard policies are disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli`,
),
isHeadlessMode: vi.fn((opts) => {
if (process.env['VITEST'] === 'true') {
@@ -1445,7 +1445,7 @@ describe('Approval mode tool exclusion logic', () => {
expect(excludedTools).toContain(ASK_USER_TOOL_NAME);
});
it('should throw an error if YOLO mode is attempted when disableYoloMode is true', async () => {
it('should throw an error if wildcard policy is attempted when disableYoloMode is true', async () => {
process.argv = ['node', 'script.js', '--yolo'];
const argv = await parseArguments(createTestMergedSettings());
const settings = createTestMergedSettings({
@@ -1455,7 +1455,7 @@ describe('Approval mode tool exclusion logic', () => {
});
await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow(
'YOLO mode is disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
'Wildcard policies are disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
);
});
@@ -1472,7 +1472,7 @@ describe('Approval mode tool exclusion logic', () => {
await expect(
loadCliConfig(settings, 'test-session', invalidArgv as CliArgs),
).rejects.toThrow(
'Invalid approval mode: invalid_mode. Valid values are: auto_edit, plan, default (yolo is mapped to allowed-tools)',
'Invalid approval mode: invalid_mode. Valid values are: auto_edit, plan, default ',
);
});
@@ -2332,7 +2332,7 @@ describe('loadCliConfig tool exclusions', () => {
vi.restoreAllMocks();
});
it('should not exclude interactive tools in interactive mode without YOLO', async () => {
it('should not exclude interactive tools in interactive mode without wildcard', async () => {
process.stdin.isTTY = true;
process.argv = ['node', 'script.js'];
const argv = await parseArguments(createTestMergedSettings());
@@ -2347,7 +2347,7 @@ describe('loadCliConfig tool exclusions', () => {
expect(config.getExcludeTools()).not.toContain('ask_user');
});
it('should not exclude interactive tools in interactive mode with YOLO', async () => {
it('should not exclude interactive tools in interactive mode with wildcard', async () => {
process.stdin.isTTY = true;
process.argv = ['node', 'script.js', '--yolo'];
const argv = await parseArguments(createTestMergedSettings());
@@ -2362,7 +2362,7 @@ describe('loadCliConfig tool exclusions', () => {
expect(config.getExcludeTools()).not.toContain('ask_user');
});
it('should exclude interactive tools in non-interactive mode without YOLO', async () => {
it('should exclude interactive tools in non-interactive mode without wildcard', async () => {
process.stdin.isTTY = false;
process.argv = ['node', 'script.js', '-p', 'test'];
const argv = await parseArguments(createTestMergedSettings());
@@ -2377,7 +2377,7 @@ describe('loadCliConfig tool exclusions', () => {
expect(config.getExcludeTools()).toContain('ask_user');
});
it('should exclude only ask_user in non-interactive mode with YOLO', async () => {
it('should exclude only ask_user in non-interactive mode with wildcard', async () => {
process.stdin.isTTY = false;
process.argv = ['node', 'script.js', '-p', 'test', '--yolo'];
const argv = await parseArguments(createTestMergedSettings());
@@ -2742,7 +2742,7 @@ describe('loadCliConfig approval mode', () => {
expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT);
});
it('should set YOLO approval mode when --yolo flag is used', async () => {
it('should set wildcard allowed tools when --yolo flag is used', async () => {
process.argv = ['node', 'script.js', '--yolo'];
const argv = await parseArguments(createTestMergedSettings());
const config = await loadCliConfig(
@@ -2751,9 +2751,10 @@ describe('loadCliConfig approval mode', () => {
argv,
);
expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT);
expect(config.getAllowedTools()).toEqual(['*']);
});
it('should set YOLO approval mode when -y flag is used', async () => {
it('should set wildcard allowed tools when -y flag is used', async () => {
process.argv = ['node', 'script.js', '-y'];
const argv = await parseArguments(createTestMergedSettings());
const config = await loadCliConfig(
@@ -2762,6 +2763,7 @@ describe('loadCliConfig approval mode', () => {
argv,
);
expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT);
expect(config.getAllowedTools()).toEqual(['*']);
});
it('should set DEFAULT approval mode when --approval-mode=default', async () => {
@@ -2786,7 +2788,7 @@ describe('loadCliConfig approval mode', () => {
expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.AUTO_EDIT);
});
it('should set YOLO approval mode when --approval-mode=yolo', async () => {
it('should set wildcard allowed tools when --approval-mode=yolo', async () => {
process.argv = ['node', 'script.js', '--approval-mode', 'yolo'];
const argv = await parseArguments(createTestMergedSettings());
const config = await loadCliConfig(
@@ -2795,6 +2797,7 @@ describe('loadCliConfig approval mode', () => {
argv,
);
expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT);
expect(config.getAllowedTools()).toEqual(['*']);
});
it('should prioritize --approval-mode over --yolo when both would be valid (but validation prevents this)', async () => {
@@ -2821,6 +2824,7 @@ describe('loadCliConfig approval mode', () => {
argv,
);
expect(config.getApprovalMode()).toBe(ServerConfig.ApprovalMode.DEFAULT);
expect(config.getAllowedTools()).toEqual(['*']);
});
it('should set Plan approval mode when --approval-mode=plan is used and plan is enabled', async () => {
@@ -3629,14 +3633,25 @@ describe('loadCliConfig disableYoloMode', () => {
expect(config.getApprovalMode()).toBe(ApprovalMode.AUTO_EDIT);
});
it('should throw if YOLO mode is attempted when disableYoloMode is true', async () => {
it('should throw if wildcard policy is attempted when disableYoloMode is true', async () => {
process.argv = ['node', 'script.js', '--yolo'];
const argv = await parseArguments(createTestMergedSettings());
const settings = createTestMergedSettings({
security: { disableYoloMode: true },
});
await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow(
'YOLO mode is disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
'Wildcard policies are disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
);
});
it('should throw if wildcard tools are requested when disableYoloMode is true', async () => {
process.argv = ['node', 'script.js', '--allowed-tools=*'];
const argv = await parseArguments(createTestMergedSettings());
const settings = createTestMergedSettings({
security: { disableYoloMode: true },
});
await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow(
'Wildcard policies are disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
);
});
});
@@ -3658,7 +3673,7 @@ describe('loadCliConfig secureModeEnabled', () => {
vi.restoreAllMocks();
});
it('should throw an error if YOLO mode is attempted when secureModeEnabled is true', async () => {
it('should throw an error if wildcard policy is attempted when secureModeEnabled is true', async () => {
process.argv = ['node', 'script.js', '--yolo'];
const argv = await parseArguments(createTestMergedSettings());
const settings = createTestMergedSettings({
@@ -3668,7 +3683,7 @@ describe('loadCliConfig secureModeEnabled', () => {
});
await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow(
'YOLO mode is disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
'Wildcard policies are disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
);
});
@@ -3682,7 +3697,21 @@ describe('loadCliConfig secureModeEnabled', () => {
});
await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow(
'YOLO mode is disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
'Wildcard policies are disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
);
});
it('should throw an error if wildcard tools are requested when secureModeEnabled is true', async () => {
process.argv = ['node', 'script.js', '--allowed-tools=*'];
const argv = await parseArguments(createTestMergedSettings());
const settings = createTestMergedSettings({
admin: {
secureModeEnabled: true,
},
});
await expect(loadCliConfig(settings, 'test-session', argv)).rejects.toThrow(
'Wildcard policies are disabled by your administrator. To enable it, please request an update to the settings at: https://goo.gle/manage-gemini-cli',
);
});
+5 -5
View File
@@ -687,7 +687,7 @@ export async function loadCliConfig(
break;
default:
throw new Error(
`Invalid approval mode: ${rawApprovalMode}. Valid values are: auto_edit, plan, default (yolo is mapped to allowed-tools)`,
`Invalid approval mode: ${rawApprovalMode}. Valid values are: auto_edit, plan, default`,
);
}
} else {
@@ -700,20 +700,20 @@ export async function loadCliConfig(
if (isYoloRequested || allowedTools.includes('*')) {
if (settings.admin?.secureModeEnabled) {
debugLogger.error(
'YOLO mode (wildcard policies) are disabled by "secureModeEnabled" setting.',
'Wildcard policies are disabled by "secureModeEnabled" setting.',
);
} else {
debugLogger.error(
'YOLO mode (wildcard policies) are disabled by the "disableYolo" setting.',
'Wildcard policies are disabled by the "disableYolo" setting.',
);
}
throw new FatalConfigError(
getAdminErrorMessage('YOLO mode', undefined /* config */),
getAdminErrorMessage('Wildcard policies', undefined /* config */),
);
}
} else if (isYoloRequested) {
debugLogger.warn(
'YOLO mode is enabled via flag or setting. All tool calls will be automatically approved by a wildcard policy.',
'Wildcard policy is enabled via flag or setting. All tool calls will be automatically approved.',
);
if (!allowedTools.includes('*')) {
allowedTools = [...allowedTools, '*'];
+1 -1
View File
@@ -2626,7 +2626,7 @@ const SETTINGS_SCHEMA = {
requiresRestart: false,
default: false,
description:
'If true, disallows YOLO mode and "Always allow" options from being used.',
'If true, disallows YOLO mode (wildcard policies) and "Always allow" options from being used.',
showInDialog: false,
mergeStrategy: MergeStrategy.REPLACE,
},
@@ -38,7 +38,7 @@ describe('ApprovalModeIndicator', () => {
const { lastFrame, waitUntilReady } = await render(
<ApprovalModeIndicator
approvalMode={ApprovalMode.DEFAULT}
isYoloMode={true}
isWildcardPolicyEnabled={true}
/>,
);
expect(lastFrame()).toMatchSnapshot();
@@ -14,13 +14,13 @@ import { Command } from '../key/keyBindings.js';
interface ApprovalModeIndicatorProps {
approvalMode: ApprovalMode;
allowPlanMode?: boolean;
isYoloMode?: boolean;
isWildcardPolicyEnabled?: boolean;
}
export const ApprovalModeIndicator: React.FC<ApprovalModeIndicatorProps> = ({
approvalMode,
allowPlanMode,
isYoloMode,
isWildcardPolicyEnabled,
}) => {
let textColor = '';
let textContent = '';
@@ -28,9 +28,9 @@ export const ApprovalModeIndicator: React.FC<ApprovalModeIndicatorProps> = ({
const cycleHint = formatCommand(Command.CYCLE_APPROVAL_MODE);
if (isYoloMode) {
if (isWildcardPolicyEnabled) {
textColor = theme.status.error;
textContent = 'YOLO';
textContent = 'WILDCARD';
subText = '';
} else {
switch (approvalMode) {
@@ -640,7 +640,7 @@ describe('Composer', () => {
},
);
it('shows ApprovalModeIndicator when YOLO mode is active and shell mode is inactive', async () => {
it('shows ApprovalModeIndicator when wildcard policy is active and shell mode is inactive', async () => {
const config = createMockConfig({
getAllowedTools: vi.fn(() => ['*']),
});
@@ -703,7 +703,7 @@ describe('Composer', () => {
},
);
it('shows minimal mode badge "YOLO" when clean UI details are hidden and YOLO mode is active', async () => {
it('shows minimal mode badge "WILDCARD" when clean UI details are hidden and wildcard policy is active', async () => {
const config = createMockConfig({
getAllowedTools: vi.fn(() => ['*']),
});
@@ -713,7 +713,7 @@ describe('Composer', () => {
});
const { lastFrame } = await renderComposer(uiState, undefined, config);
expect(lastFrame()).toContain('YOLO');
expect(lastFrame()).toContain('WILDCARD');
});
it('hides minimal mode badge while loading in clean mode', async () => {
+2 -2
View File
@@ -77,7 +77,7 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => {
const hasToast = shouldShowToast(uiState);
const hideUiDetailsForSuggestions =
suggestionsVisible && suggestionsPosition === 'above';
const isYoloMode = config.getAllowedTools()?.includes('*');
const isWildcardPolicyEnabled = config.getAllowedTools()?.includes('*');
// Mini Mode VIP Flags (Pure Content Triggers)
const showMinimalToast = hasToast;
@@ -148,7 +148,7 @@ export const Composer = ({ isFocused = true }: { isFocused?: boolean }) => {
shellModeActive={uiState.shellModeActive}
setShellModeActive={uiActions.setShellModeActive}
approvalMode={uiState.showApprovalModeIndicator}
isYoloMode={isYoloMode}
isWildcardPolicyEnabled={isWildcardPolicyEnabled}
onEscapePromptChange={uiActions.onEscapePromptChange}
focus={isFocused}
vimHandleInput={uiActions.vimHandleInput}
@@ -110,7 +110,7 @@ export interface InputPromptProps {
shellModeActive: boolean;
setShellModeActive: (value: boolean) => void;
approvalMode: ApprovalMode;
isYoloMode?: boolean;
isWildcardPolicyEnabled?: boolean;
onEscapePromptChange?: (showPrompt: boolean) => void;
onSuggestionsVisibilityChange?: (visible: boolean) => void;
vimHandleInput?: (key: Key) => boolean;
@@ -206,7 +206,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
shellModeActive,
setShellModeActive,
approvalMode,
isYoloMode,
isWildcardPolicyEnabled,
onEscapePromptChange,
onSuggestionsVisibilityChange,
vimHandleInput,
@@ -1491,7 +1491,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
const showAutoAcceptStyling =
!shellModeActive && approvalMode === ApprovalMode.AUTO_EDIT;
const showYoloStyling = !shellModeActive && isYoloMode;
const showWildcardStyling = !shellModeActive && isWildcardPolicyEnabled;
const showPlanStyling =
!shellModeActive && approvalMode === ApprovalMode.PLAN;
@@ -1500,9 +1500,9 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
if (shellModeActive) {
statusColor = theme.ui.symbol;
statusText = 'Shell mode';
} else if (showYoloStyling) {
} else if (showWildcardStyling) {
statusColor = theme.status.error;
statusText = 'YOLO mode';
statusText = 'Wildcard policy';
} else if (showPlanStyling) {
statusColor = theme.status.success;
statusText = 'Plan mode';
@@ -1590,7 +1590,7 @@ export const InputPrompt: React.FC<InputPromptProps> = ({
)
) : commandSearchActive ? (
<Text color={theme.text.accent}>(r:) </Text>
) : showYoloStyling ? (
) : showWildcardStyling ? (
'*'
) : (
'>'
@@ -26,6 +26,6 @@ exports[`ApprovalModeIndicator > renders correctly for PLAN mode 1`] = `
`;
exports[`ApprovalModeIndicator > renders correctly for YOLO mode 1`] = `
"YOLO
"WILDCARD
"
`;