Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion docs/tos-privacy.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,4 +93,4 @@ backend, these Terms of Service and Privacy Notice documents apply:

You may opt-out from sending Gemini CLI Usage Statistics to Google by following
the instructions available here:
[Usage Statistics Configuration](https://github.com/google-gemini/gemini-cli/blob/main/docs/get-started/configuration.md#usage-statistics).
[Usage Statistics Configuration](https://github.com/google-gemini/gemini-cli/blob/main/docs/reference/configuration.md#usage-statistics).
41 changes: 41 additions & 0 deletions packages/cli/src/ui/contexts/ToolActionsContext.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import {
MessageBusType,
IdeClient,
CoreToolCallStatus,
type SerializableConfirmationDetails,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The import of SerializableConfirmationDetails is unnecessary in this test file as it's only used for a type assertion, which can be avoided by directly defining the legacyTool with the LegacyConfirmationDetails type.

  CoreToolCallStatus,
}

} from '@google/gemini-cli-core';
import { type IndividualToolCallDisplay } from '../types.js';

Expand Down Expand Up @@ -182,4 +183,44 @@ describe('ToolActionsContext', () => {

expect(result.current.isDiffingEnabled).toBe(false);
});

it('calls local onConfirm for tools without correlationId', async () => {
const mockOnConfirm = vi.fn().mockResolvedValue(undefined);
const legacyTool: IndividualToolCallDisplay = {
callId: 'legacy-call',
name: 'legacy-tool',
description: 'desc',
status: CoreToolCallStatus.AwaitingApproval,
resultDisplay: undefined,
confirmationDetails: {
type: 'exec',
title: 'exec',
command: 'ls',
rootCommand: 'ls',
rootCommands: ['ls'],
onConfirm: mockOnConfirm,
} as unknown as SerializableConfirmationDetails,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The type assertion as unknown as SerializableConfirmationDetails is a workaround that can be avoided by defining legacyTool with the correct LegacyConfirmationDetails type, which is now available. This improves type safety and readability.

        onConfirm: mockOnConfirm,
      },
    };

};

const { result } = renderHook(() => useToolActions(), {
wrapper: ({ children }) => (
<ToolActionsProvider config={mockConfig} toolCalls={[legacyTool]}>
{children}
</ToolActionsProvider>
),
});

await act(async () => {
await result.current.confirm(
'legacy-call',
ToolConfirmationOutcome.ProceedOnce,
);
});

expect(mockOnConfirm).toHaveBeenCalledWith(
ToolConfirmationOutcome.ProceedOnce,
undefined,
);
expect(mockMessageBus.publish).not.toHaveBeenCalled();
});
});
28 changes: 27 additions & 1 deletion packages/cli/src/ui/contexts/ToolActionsContext.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,28 @@ import {
MessageBusType,
type Config,
type ToolConfirmationPayload,
type SerializableConfirmationDetails,
debugLogger,
} from '@google/gemini-cli-core';
import type { IndividualToolCallDisplay } from '../types.js';

type LegacyConfirmationDetails = SerializableConfirmationDetails & {
onConfirm: (
outcome: ToolConfirmationOutcome,
payload?: ToolConfirmationPayload,
) => Promise<void>;
};

function hasLegacyCallback(
details: SerializableConfirmationDetails | undefined,
): details is LegacyConfirmationDetails {
return (
!!details &&
'onConfirm' in details &&
typeof details.onConfirm === 'function'
);
}

interface ToolActionsContextValue {
confirm: (
callId: string,
Expand Down Expand Up @@ -125,7 +143,15 @@ export const ToolActionsProvider: React.FC<ToolActionsProviderProps> = (
return;
}

debugLogger.warn(`ToolActions: No correlationId for ${callId}`);
// 3. Fallback: Legacy Callback
if (hasLegacyCallback(details)) {
await details.onConfirm(outcome, payload);
return;
}

debugLogger.warn(
`ToolActions: No correlationId or callback for ${callId}`,
);
},
[config, ideClient, toolCalls, isDiffingEnabled],
);
Expand Down
Loading