mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-14 22:02:59 -07:00
Default-enable.
This commit is contained in:
@@ -0,0 +1,61 @@
|
||||
import { evaluate } from 'mathjs';
|
||||
|
||||
export interface CalculatorState {
|
||||
display: string;
|
||||
equation: string;
|
||||
lastResult: string | null;
|
||||
}
|
||||
|
||||
export const initialState: CalculatorState = {
|
||||
display: '0',
|
||||
equation: '',
|
||||
lastResult: null,
|
||||
};
|
||||
|
||||
export function handleInput(state: CalculatorState, input: string): CalculatorState {
|
||||
if (/[0-9]/.test(input)) {
|
||||
if (state.display === '0' || state.lastResult !== null) {
|
||||
return { ...state, display: input, lastResult: null };
|
||||
} else {
|
||||
return { ...state, display: state.display + input };
|
||||
}
|
||||
} else if (input === '.') {
|
||||
if (!state.display.includes('.')) {
|
||||
return { ...state, display: state.display + '.' };
|
||||
}
|
||||
} else if (['+', '-', '*', '/'].includes(input)) {
|
||||
return {
|
||||
...state,
|
||||
equation: `${state.display} ${input} `,
|
||||
display: '0',
|
||||
};
|
||||
}
|
||||
return state;
|
||||
}
|
||||
|
||||
export function calculate(state: CalculatorState): CalculatorState {
|
||||
try {
|
||||
const fullEquation = state.equation + state.display;
|
||||
const result = evaluate(fullEquation);
|
||||
const resultStr = result.toString();
|
||||
return {
|
||||
display: resultStr,
|
||||
equation: '',
|
||||
lastResult: resultStr,
|
||||
};
|
||||
} catch (error) {
|
||||
return {
|
||||
display: 'Error',
|
||||
equation: '',
|
||||
lastResult: null,
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
export function deleteLast(state: CalculatorState): CalculatorState {
|
||||
if (state.display.length > 1) {
|
||||
return { ...state, display: state.display.slice(0, -1) };
|
||||
} else {
|
||||
return { ...state, display: '0' };
|
||||
}
|
||||
}
|
||||
@@ -1867,6 +1867,32 @@ describe('loadCliConfig with admin.mcp.config', () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadCliConfig deepValidation', () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]);
|
||||
});
|
||||
|
||||
it('should enable deepValidation by default', async () => {
|
||||
process.argv = ['node', 'script.js'];
|
||||
const argv = await parseArguments(createTestMergedSettings());
|
||||
const settings = createTestMergedSettings();
|
||||
const config = await loadCliConfig(settings, 'test-session', argv);
|
||||
expect(config.isDeepValidationEnabled()).toBe(true);
|
||||
});
|
||||
|
||||
it('should allow disabling deepValidation via settings', async () => {
|
||||
process.argv = ['node', 'script.js'];
|
||||
const argv = await parseArguments(createTestMergedSettings());
|
||||
const settings = createTestMergedSettings({
|
||||
general: {
|
||||
deepValidation: false,
|
||||
},
|
||||
});
|
||||
const config = await loadCliConfig(settings, 'test-session', argv);
|
||||
expect(config.isDeepValidationEnabled()).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
describe('loadCliConfig model selection', () => {
|
||||
beforeEach(() => {
|
||||
vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]);
|
||||
|
||||
@@ -900,7 +900,7 @@ export async function loadCliConfig(
|
||||
memoryBoundaryMarkers: settings.context?.memoryBoundaryMarkers,
|
||||
importFormat: settings.context?.importFormat,
|
||||
debugMode,
|
||||
deepValidation: settings.general?.deepValidation,
|
||||
deepValidation: settings.general?.deepValidation ?? true,
|
||||
question,
|
||||
worktreeSettings,
|
||||
|
||||
|
||||
@@ -241,7 +241,7 @@ const SETTINGS_SCHEMA = {
|
||||
label: 'Deep Validation',
|
||||
category: 'General',
|
||||
requiresRestart: false,
|
||||
default: false,
|
||||
default: true,
|
||||
description:
|
||||
'Run a subagent after the main agent finishes to perform final validation.',
|
||||
showInDialog: true,
|
||||
|
||||
@@ -2051,6 +2051,11 @@ export class Config implements McpContext, AgentLoopContext {
|
||||
getDebugMode(): boolean {
|
||||
return this.debugMode;
|
||||
}
|
||||
|
||||
isDeepValidationEnabled(): boolean {
|
||||
return this.deepValidation;
|
||||
}
|
||||
|
||||
getQuestion(): string | undefined {
|
||||
return this.question;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user