mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-05-15 06:12:50 -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', () => {
|
describe('loadCliConfig model selection', () => {
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]);
|
vi.spyOn(ExtensionManager.prototype, 'getExtensions').mockReturnValue([]);
|
||||||
|
|||||||
@@ -900,7 +900,7 @@ export async function loadCliConfig(
|
|||||||
memoryBoundaryMarkers: settings.context?.memoryBoundaryMarkers,
|
memoryBoundaryMarkers: settings.context?.memoryBoundaryMarkers,
|
||||||
importFormat: settings.context?.importFormat,
|
importFormat: settings.context?.importFormat,
|
||||||
debugMode,
|
debugMode,
|
||||||
deepValidation: settings.general?.deepValidation,
|
deepValidation: settings.general?.deepValidation ?? true,
|
||||||
question,
|
question,
|
||||||
worktreeSettings,
|
worktreeSettings,
|
||||||
|
|
||||||
|
|||||||
@@ -241,7 +241,7 @@ const SETTINGS_SCHEMA = {
|
|||||||
label: 'Deep Validation',
|
label: 'Deep Validation',
|
||||||
category: 'General',
|
category: 'General',
|
||||||
requiresRestart: false,
|
requiresRestart: false,
|
||||||
default: false,
|
default: true,
|
||||||
description:
|
description:
|
||||||
'Run a subagent after the main agent finishes to perform final validation.',
|
'Run a subagent after the main agent finishes to perform final validation.',
|
||||||
showInDialog: true,
|
showInDialog: true,
|
||||||
|
|||||||
@@ -2051,6 +2051,11 @@ export class Config implements McpContext, AgentLoopContext {
|
|||||||
getDebugMode(): boolean {
|
getDebugMode(): boolean {
|
||||||
return this.debugMode;
|
return this.debugMode;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isDeepValidationEnabled(): boolean {
|
||||||
|
return this.deepValidation;
|
||||||
|
}
|
||||||
|
|
||||||
getQuestion(): string | undefined {
|
getQuestion(): string | undefined {
|
||||||
return this.question;
|
return this.question;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user