mirror of
https://github.com/google-gemini/gemini-cli.git
synced 2026-04-11 13:51:10 -07:00
Disallow unsafe type assertions (#18688)
This commit is contained in:
committed by
GitHub
parent
bce1caefd0
commit
fd65416a2f
@@ -191,6 +191,7 @@ export class ChatRecordingService {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
'code' in error &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
(error as NodeJS.ErrnoException).code === 'ENOSPC'
|
||||
) {
|
||||
this.conversationFile = null;
|
||||
@@ -420,6 +421,7 @@ export class ChatRecordingService {
|
||||
this.cachedLastConvData = fs.readFileSync(this.conversationFile!, 'utf8');
|
||||
return JSON.parse(this.cachedLastConvData);
|
||||
} catch (error) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
if ((error as NodeJS.ErrnoException).code !== 'ENOENT') {
|
||||
debugLogger.error('Error reading conversation file.', error);
|
||||
throw error;
|
||||
@@ -460,6 +462,7 @@ export class ChatRecordingService {
|
||||
if (
|
||||
error instanceof Error &&
|
||||
'code' in error &&
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
(error as NodeJS.ErrnoException).code === 'ENOSPC'
|
||||
) {
|
||||
this.conversationFile = null;
|
||||
|
||||
@@ -449,6 +449,7 @@ export class LoopDetectionService {
|
||||
return false;
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const flashConfidence = flashResult[
|
||||
'unproductive_state_confidence'
|
||||
] as number;
|
||||
@@ -490,7 +491,8 @@ export class LoopDetectionService {
|
||||
);
|
||||
|
||||
const mainModelConfidence = mainModelResult
|
||||
? (mainModelResult['unproductive_state_confidence'] as number)
|
||||
? // eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
(mainModelResult['unproductive_state_confidence'] as number)
|
||||
: 0;
|
||||
|
||||
logLlmLoopCheck(
|
||||
|
||||
@@ -245,6 +245,7 @@ export class ModelConfigService {
|
||||
let matchedLevel = 0; // Default to Global
|
||||
const isMatch = matchEntries.every(([key, value]) => {
|
||||
if (key === 'model') {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const level = modelToLevel.get(value as string);
|
||||
if (level === undefined) return false;
|
||||
matchedLevel = level;
|
||||
@@ -253,6 +254,7 @@ export class ModelConfigService {
|
||||
if (key === 'overrideScope' && value === 'core') {
|
||||
return context.overrideScope === 'core' || !context.overrideScope;
|
||||
}
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
return context[key as keyof ModelConfigKey] === value;
|
||||
});
|
||||
|
||||
@@ -291,6 +293,7 @@ export class ModelConfigService {
|
||||
);
|
||||
}
|
||||
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
return {
|
||||
model: resolved.model,
|
||||
generateContentConfig: resolved.generateContentConfig,
|
||||
@@ -321,7 +324,9 @@ export class ModelConfigService {
|
||||
config2: GenerateContentConfig | undefined,
|
||||
): GenerateContentConfig {
|
||||
return ModelConfigService.genericDeepMerge(
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
config1 as Record<string, unknown> | undefined,
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
config2 as Record<string, unknown> | undefined,
|
||||
) as GenerateContentConfig;
|
||||
}
|
||||
|
||||
@@ -13,6 +13,7 @@ export const makeResolvedModelConfig = (
|
||||
model: string,
|
||||
overrides: Partial<ResolvedModelConfig['generateContentConfig']> = {},
|
||||
): ResolvedModelConfig =>
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
({
|
||||
model,
|
||||
generateContentConfig: {
|
||||
|
||||
@@ -510,6 +510,7 @@ export class ShellExecutionService {
|
||||
|
||||
return { pid: child.pid, result };
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const error = e as Error;
|
||||
return {
|
||||
pid: undefined,
|
||||
@@ -778,6 +779,7 @@ export class ShellExecutionService {
|
||||
this.activePtys.delete(ptyProcess.pid);
|
||||
// Attempt to destroy the PTY to ensure FD is closed
|
||||
try {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
(ptyProcess as IPty & { destroy?: () => void }).destroy?.();
|
||||
} catch {
|
||||
// Ignore errors during cleanup
|
||||
@@ -860,6 +862,7 @@ export class ShellExecutionService {
|
||||
|
||||
return { pid: ptyProcess.pid, result };
|
||||
} catch (e) {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const error = e as Error;
|
||||
if (error.message.includes('posix_spawnp failed')) {
|
||||
onOutputEvent({
|
||||
@@ -1105,6 +1108,7 @@ export class ShellExecutionService {
|
||||
} catch (e) {
|
||||
// Ignore errors if the pty has already exited, which can happen
|
||||
// due to a race condition between the exit event and this call.
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const err = e as { code?: string; message?: string };
|
||||
const isEsrch = err.code === 'ESRCH';
|
||||
const isWindowsPtyError = err.message?.includes(
|
||||
|
||||
@@ -189,6 +189,7 @@ export class ToolOutputMaskingService {
|
||||
await fsPromises.writeFile(filePath, content, 'utf-8');
|
||||
|
||||
const originalResponse =
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
(part.functionResponse.response as Record<string, unknown>) || {};
|
||||
|
||||
const totalLines = content.split('\n').length;
|
||||
@@ -268,6 +269,7 @@ export class ToolOutputMaskingService {
|
||||
|
||||
private getToolOutputContent(part: Part): string | null {
|
||||
if (!part.functionResponse) return null;
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const response = part.functionResponse.response as Record<string, unknown>;
|
||||
if (!response) return null;
|
||||
|
||||
@@ -286,6 +288,7 @@ export class ToolOutputMaskingService {
|
||||
}
|
||||
|
||||
private formatShellPreview(response: Record<string, unknown>): string {
|
||||
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
|
||||
const content = (response['output'] || response['stdout'] || '') as string;
|
||||
if (typeof content !== 'string') {
|
||||
return typeof content === 'object'
|
||||
|
||||
Reference in New Issue
Block a user