Disallow unsafe type assertions (#18688)

This commit is contained in:
Christian Gunderman
2026-02-10 00:10:15 +00:00
committed by GitHub
parent bce1caefd0
commit fd65416a2f
188 changed files with 592 additions and 47 deletions

View File

@@ -467,6 +467,7 @@ export const useSlashCommandProcessor = (
actions.openModelDialog();
return { type: 'handled' };
case 'agentConfig': {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const props = result.props as Record<string, unknown>;
if (
!props ||
@@ -482,12 +483,14 @@ export const useSlashCommandProcessor = (
actions.openAgentConfigDialog(
props['name'],
props['displayName'],
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
props['definition'] as AgentDefinition,
);
return { type: 'handled' };
}
case 'permissions':
actions.openPermissionsDialog(
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
result.props as { targetDirectory?: string },
);
return { type: 'handled' };

View File

@@ -102,6 +102,7 @@ export function useApprovalModeIndicator({
addItem(
{
type: MessageType.INFO,
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
text: (e as Error).message,
},
Date.now(),

View File

@@ -46,7 +46,6 @@ import type {
ToolCallResponseInfo,
GeminiErrorEventValue,
RetryAttemptPayload,
ToolCallConfirmationDetails,
} from '@google/gemini-cli-core';
import { type Part, type PartListUnion, FinishReason } from '@google/genai';
import type {
@@ -427,6 +426,7 @@ export const useGeminiStream = (
(tc) =>
tc.status === 'executing' && tc.request.name === 'run_shell_command',
);
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return (executingShellTool as TrackedExecutingToolCall | undefined)?.pid;
}, [toolCalls]);
@@ -551,6 +551,7 @@ export const useGeminiStream = (
// If it is a shell command, we update the status to Canceled and clear the output
// to avoid artifacts, then add it to history immediately.
if (isShellCommand) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const toolGroup = pendingHistoryItemRef.current as HistoryItemToolGroup;
const updatedTools = toolGroup.tools.map((tool) => {
if (tool.name === SHELL_COMMAND_NAME) {
@@ -764,6 +765,7 @@ export const useGeminiStream = (
if (splitPoint === newGeminiMessageBuffer.length) {
// Update the existing message with accumulated content
setPendingHistoryItem((item) => ({
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
type: item?.type as 'gemini' | 'gemini_content',
text: newGeminiMessageBuffer,
}));
@@ -780,6 +782,7 @@ export const useGeminiStream = (
const afterText = newGeminiMessageBuffer.substring(splitPoint);
addItem(
{
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
type: pendingHistoryItemRef.current?.type as
| 'gemini'
| 'gemini_content',
@@ -1372,13 +1375,10 @@ export const useGeminiStream = (
// Process pending tool calls sequentially to reduce UI chaos
for (const call of awaitingApprovalCalls) {
if (
(call.confirmationDetails as ToolCallConfirmationDetails)?.onConfirm
) {
const details = call.confirmationDetails;
if (details && 'onConfirm' in details) {
try {
await (
call.confirmationDetails as ToolCallConfirmationDetails
).onConfirm(ToolConfirmationOutcome.ProceedOnce);
await details.onConfirm(ToolConfirmationOutcome.ProceedOnce);
} catch (error) {
debugLogger.warn(
`Failed to auto-approve tool call ${call.request.callId}:`,
@@ -1444,7 +1444,9 @@ export const useGeminiStream = (
const pid = data?.pid;
if (isShell && pid) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const command = (data?.['command'] as string) ?? 'shell';
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const initialOutput = (data?.['initialOutput'] as string) ?? '';
registerBackgroundShell(pid, command, initialOutput);

View File

@@ -62,6 +62,7 @@ export function useHistory({
isResuming: boolean = false,
): number => {
const id = getNextMessageId(baseTimestamp);
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const newItem: HistoryItem = { ...itemData, id } as HistoryItem;
setHistory((prevHistory) => {
@@ -139,6 +140,7 @@ export function useHistory({
// Apply updates based on whether it's an object or a function
const newUpdates =
typeof updates === 'function' ? updates(item) : updates;
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
return { ...item, ...newUpdates } as HistoryItem;
}
return item;

View File

@@ -38,6 +38,7 @@ async function finishAddingDirectories(
await refreshServerHierarchicalMemory(config);
}
} catch (error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
errors.push(`Error refreshing memory: ${(error as Error).message}`);
}

View File

@@ -106,6 +106,7 @@ async function getRemoteDataCollectionOptIn(
return resp.freeTierDataCollectionOptin;
} catch (error: unknown) {
if (error && typeof error === 'object' && 'response' in error) {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const gaxiosError = error as {
response?: {
status?: unknown;

View File

@@ -127,6 +127,7 @@ export function useReactToolScheduler(
existingTrackedCall?.responseSubmittedToGemini ?? false;
if (coreTc.status === 'executing') {
// eslint-disable-next-line @typescript-eslint/no-unsafe-type-assertion
const liveOutput = (existingTrackedCall as TrackedExecutingToolCall)
?.liveOutput;
return {