mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-05 10:51:12 -07:00
feat(plan): inject message when user manually exits Plan mode (#20203)
This commit is contained in:
60
packages/core/src/utils/approvalModeUtils.test.ts
Normal file
60
packages/core/src/utils/approvalModeUtils.test.ts
Normal file
@@ -0,0 +1,60 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { describe, it, expect } from 'vitest';
|
||||
import { ApprovalMode } from '../policy/types.js';
|
||||
import {
|
||||
getApprovalModeDescription,
|
||||
getPlanModeExitMessage,
|
||||
} from './approvalModeUtils.js';
|
||||
|
||||
describe('approvalModeUtils', () => {
|
||||
describe('getApprovalModeDescription', () => {
|
||||
it('should return correct description for DEFAULT mode', () => {
|
||||
expect(getApprovalModeDescription(ApprovalMode.DEFAULT)).toBe(
|
||||
'Default mode (edits will require confirmation)',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct description for AUTO_EDIT mode', () => {
|
||||
expect(getApprovalModeDescription(ApprovalMode.AUTO_EDIT)).toBe(
|
||||
'Auto-Edit mode (edits will be applied automatically)',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct description for PLAN mode', () => {
|
||||
expect(getApprovalModeDescription(ApprovalMode.PLAN)).toBe(
|
||||
'Plan mode (read-only planning)',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return correct description for YOLO mode', () => {
|
||||
expect(getApprovalModeDescription(ApprovalMode.YOLO)).toBe(
|
||||
'YOLO mode (all tool calls auto-approved)',
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
describe('getPlanModeExitMessage', () => {
|
||||
it('should return standard message when not manual', () => {
|
||||
expect(getPlanModeExitMessage(ApprovalMode.DEFAULT, false)).toBe(
|
||||
'Plan approved. Switching to Default mode (edits will require confirmation).',
|
||||
);
|
||||
});
|
||||
|
||||
it('should return manual message when manual is true', () => {
|
||||
expect(getPlanModeExitMessage(ApprovalMode.AUTO_EDIT, true)).toBe(
|
||||
'User has manually exited Plan Mode. Switching to Auto-Edit mode (edits will be applied automatically).',
|
||||
);
|
||||
});
|
||||
|
||||
it('should default to non-manual message', () => {
|
||||
expect(getPlanModeExitMessage(ApprovalMode.YOLO)).toBe(
|
||||
'Plan approved. Switching to YOLO mode (all tool calls auto-approved).',
|
||||
);
|
||||
});
|
||||
});
|
||||
});
|
||||
40
packages/core/src/utils/approvalModeUtils.ts
Normal file
40
packages/core/src/utils/approvalModeUtils.ts
Normal file
@@ -0,0 +1,40 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright 2026 Google LLC
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
import { ApprovalMode } from '../policy/types.js';
|
||||
import { checkExhaustive } from './checks.js';
|
||||
|
||||
/**
|
||||
* Returns a human-readable description for an approval mode.
|
||||
*/
|
||||
export function getApprovalModeDescription(mode: ApprovalMode): string {
|
||||
switch (mode) {
|
||||
case ApprovalMode.AUTO_EDIT:
|
||||
return 'Auto-Edit mode (edits will be applied automatically)';
|
||||
case ApprovalMode.DEFAULT:
|
||||
return 'Default mode (edits will require confirmation)';
|
||||
case ApprovalMode.PLAN:
|
||||
return 'Plan mode (read-only planning)';
|
||||
case ApprovalMode.YOLO:
|
||||
return 'YOLO mode (all tool calls auto-approved)';
|
||||
default:
|
||||
return checkExhaustive(mode);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Generates a consistent message for plan mode transitions.
|
||||
*/
|
||||
export function getPlanModeExitMessage(
|
||||
newMode: ApprovalMode,
|
||||
isManual: boolean = false,
|
||||
): string {
|
||||
const description = getApprovalModeDescription(newMode);
|
||||
const prefix = isManual
|
||||
? 'User has manually exited Plan Mode.'
|
||||
: 'Plan approved.';
|
||||
return `${prefix} Switching to ${description}.`;
|
||||
}
|
||||
Reference in New Issue
Block a user