Skip to content
Closed
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
5 changes: 2 additions & 3 deletions packages/cli/src/ui/commands/mcpCommand.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,8 @@ import {
getMCPDiscoveryState,
DiscoveredMCPTool,
type MessageBus,
type CallableToolWithProgress,
} from '@google/gemini-cli-core';

import type { CallableTool } from '@google/genai';
import { MessageType } from '../types.js';

vi.mock('@google/gemini-cli-core', async (importOriginal) => {
Expand Down Expand Up @@ -53,7 +52,7 @@ const createMockMCPTool = (
{
callTool: vi.fn(),
tool: vi.fn(),
} as unknown as CallableTool,
} as unknown as CallableToolWithProgress,
serverName,
name,
description || 'Mock tool description',
Expand Down
14 changes: 13 additions & 1 deletion packages/cli/src/ui/components/messages/ToolMessage.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import type React from 'react';
import { ToolMessage, type ToolMessageProps } from './ToolMessage.js';
import { describe, it, expect, vi } from 'vitest';
import { describe, it, expect, vi, beforeEach } from 'vitest';
import { StreamingState } from '../../types.js';
import { Text } from 'ink';
import { type AnsiOutput, CoreToolCallStatus } from '@google/gemini-cli-core';
Expand Down Expand Up @@ -299,6 +299,18 @@ describe('<ToolMessage />', () => {
expect(lowEmphasisFrame()).toMatchSnapshot();
});

it('renders MCPProgressIndicator when executing with progress', () => {
const { lastFrame } = renderWithContext(
<ToolMessage
{...baseProps}
status={CoreToolCallStatus.Executing}
mcpProgress={{ progress: 50, total: 100, message: 'Processing...' }}
/>,
StreamingState.Responding,
);
expect(lastFrame()).toMatchSnapshot();
});

it('renders AnsiOutputText for AnsiOutput results', () => {
const ansiResult: AnsiOutput = [
[
Expand Down
15 changes: 14 additions & 1 deletion packages/cli/src/ui/components/messages/ToolMessage.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,15 @@ import {
ToolStatusIndicator,
ToolInfo,
TrailingIndicator,
MCPProgressIndicator,
type TextEmphasis,
STATUS_INDICATOR_WIDTH,
isThisShellFocusable as checkIsShellFocusable,
isThisShellFocused as checkIsShellFocused,
useFocusHint,
FocusHint,
} from './ToolShared.js';
import { type Config } from '@google/gemini-cli-core';
import { type Config, CoreToolCallStatus } from '@google/gemini-cli-core';
import { ShellInputPrompt } from '../ShellInputPrompt.js';

export type { TextEmphasis };
Expand Down Expand Up @@ -55,6 +56,7 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
embeddedShellFocused,
ptyId,
config,
mcpProgress,
}) => {
const isThisShellFocused = checkIsShellFocused(
name,
Expand Down Expand Up @@ -108,6 +110,17 @@ export const ToolMessage: React.FC<ToolMessageProps> = ({
paddingX={1}
flexDirection="column"
>
{status === CoreToolCallStatus.Executing && mcpProgress && (
<MCPProgressIndicator
progress={mcpProgress.progress}
total={mcpProgress.total}
message={mcpProgress.message}
barWidth={Math.max(
10,
Math.min(Math.floor(terminalWidth * 0.4), 40),
)}
/>
)}
<ToolResultDisplay
resultDisplay={resultDisplay}
availableTerminalHeight={availableTerminalHeight}
Expand Down
58 changes: 58 additions & 0 deletions packages/cli/src/ui/components/messages/ToolShared.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
/**
* @license
* Copyright 2025 Google LLC
* SPDX-License-Identifier: Apache-2.0
*/

import { render } from '../../../test-utils/render.js';
import { MCPProgressIndicator } from './ToolShared.js';
import { describe, it, expect } from 'vitest';

describe('MCPProgressIndicator', () => {
it('renders determinate progress bar at 50%', () => {
const { lastFrame } = render(
<MCPProgressIndicator progress={50} total={100} barWidth={20} />,
);
expect(lastFrame()).toMatchSnapshot();
});

it('renders fully complete progress bar', () => {
const { lastFrame } = render(
<MCPProgressIndicator progress={100} total={100} barWidth={20} />,
);
expect(lastFrame()).toMatchSnapshot();
});

it('renders indeterminate progress without total', () => {
const { lastFrame } = render(
<MCPProgressIndicator progress={5} barWidth={20} />,
);
expect(lastFrame()).toMatchSnapshot();
});

it('renders progress message when provided', () => {
const { lastFrame } = render(
<MCPProgressIndicator
progress={50}
total={100}
message="Downloading..."
barWidth={20}
/>,
);
expect(lastFrame()).toMatchSnapshot();
});

it('scales bar width correctly', () => {
const { lastFrame } = render(
<MCPProgressIndicator progress={50} total={100} barWidth={40} />,
);
expect(lastFrame()).toMatchSnapshot();
});

it('clamps progress exceeding total', () => {
const { lastFrame } = render(
<MCPProgressIndicator progress={150} total={100} barWidth={20} />,
);
expect(lastFrame()).toMatchSnapshot();
});
});
52 changes: 52 additions & 0 deletions packages/cli/src/ui/components/messages/ToolShared.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -233,3 +233,55 @@ export const TrailingIndicator: React.FC = () => (
</Text>
);

export interface MCPProgressIndicatorProps {
progress: number;
total?: number;
message?: string;
barWidth: number;
}

/**
* Values are clamped to prevent crashes from negative repeat counts
* when progress > total (which can happen with misbehaving MCP servers).
*/
export const MCPProgressIndicator: React.FC<MCPProgressIndicatorProps> = ({
progress,
total,
message,
barWidth,
}) => {
const percentage =
total && total > 0
? Math.min(100, Math.round((progress / total) * 100))
: null;

let rawFilled: number;
if (total && total > 0) {
rawFilled = Math.round((progress / total) * barWidth);
} else {
rawFilled = Math.floor(progress) % (barWidth + 1);
}

const filled = Math.max(
0,
Math.min(Number.isFinite(rawFilled) ? rawFilled : 0, barWidth),
);
const empty = Math.max(0, barWidth - filled);
const progressBar = '\u2588'.repeat(filled) + '\u2591'.repeat(empty);

return (
<Box flexDirection="column" marginTop={1}>
<Box>
<Text color={theme.text.accent}>
{progressBar} {percentage !== null ? `${percentage}%` : `${progress}`}
</Text>
</Box>
{message && (
<Text color={theme.text.secondary} wrap="truncate">
{message}
</Text>
)}
</Box>
);
};
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ exports[`<ToolMessage /> > renders DiffRenderer for diff results 1`] = `
│ 1 + new │"
`;

exports[`<ToolMessage /> > renders MCPProgressIndicator when executing with progress 1`] = `
"╭──────────────────────────────────────────────────────────────────────────────╮
│ MockRespondingSpinnertest-tool A tool for testing │
│ │
│ │
│ ████████████████░░░░░░░░░░░░░░░░ 50% │
│ Processing... │
│ Test result │"
`;

exports[`<ToolMessage /> > renders basic tool information 1`] = `
"╭──────────────────────────────────────────────────────────────────────────────╮
│ ✓ test-tool A tool for testing │
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`MCPProgressIndicator > clamps progress exceeding total 1`] = `
"
████████████████████ 100%"
`;

exports[`MCPProgressIndicator > renders determinate progress bar at 50% 1`] = `
"
██████████░░░░░░░░░░ 50%"
`;

exports[`MCPProgressIndicator > renders fully complete progress bar 1`] = `
"
████████████████████ 100%"
`;

exports[`MCPProgressIndicator > renders indeterminate progress without total 1`] = `
"
█████░░░░░░░░░░░░░░░ 5"
`;

exports[`MCPProgressIndicator > renders progress message when provided 1`] = `
"
██████████░░░░░░░░░░ 50%
Downloading..."
`;

exports[`MCPProgressIndicator > scales bar width correctly 1`] = `
"
████████████████████░░░░░░░░░░░░░░░░░░░░ 50%"
`;
4 changes: 4 additions & 0 deletions packages/cli/src/ui/hooks/toolMapping.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
debugLogger,
CoreToolCallStatus,
} from '@google/gemini-cli-core';
import type { Progress } from '@modelcontextprotocol/sdk/types.js';
import {
type HistoryItemToolGroup,
type IndividualToolCallDisplay,
Expand Down Expand Up @@ -54,6 +55,7 @@ export function mapToDisplay(
let outputFile: string | undefined = undefined;
let ptyId: number | undefined = undefined;
let correlationId: string | undefined = undefined;
let mcpProgress: Progress | undefined = undefined;

switch (call.status) {
case CoreToolCallStatus.Success:
Expand All @@ -72,6 +74,7 @@ export function mapToDisplay(
case CoreToolCallStatus.Executing:
resultDisplay = call.liveOutput;
ptyId = call.pid;
mcpProgress = call.mcpProgress;
break;
case CoreToolCallStatus.Scheduled:
case CoreToolCallStatus.Validating:
Expand All @@ -96,6 +99,7 @@ export function mapToDisplay(
ptyId,
correlationId,
approvalMode: call.approvalMode,
mcpProgress,
};
});

Expand Down
2 changes: 2 additions & 0 deletions packages/cli/src/ui/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
CoreToolCallStatus,
checkExhaustive,
} from '@google/gemini-cli-core';
import type { Progress } from '@modelcontextprotocol/sdk/types.js';
import type { PartListUnion } from '@google/genai';
import { type ReactNode } from 'react';

Expand Down Expand Up @@ -108,6 +109,7 @@ export interface IndividualToolCallDisplay {
outputFile?: string;
correlationId?: string;
approvalMode?: ApprovalMode;
mcpProgress?: Progress;
}

export interface CompressionProps {
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/agents/local-executor.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import {
DiscoveredMCPTool,
MCP_QUALIFIED_NAME_SEPARATOR,
} from '../tools/mcp-tool.js';
import type { CallableToolWithProgress } from '../tools/mcp-client.js';
import { LSTool } from '../tools/ls.js';
import { LS_TOOL_NAME, READ_FILE_TOOL_NAME } from '../tools/tool-names.js';
import {
Expand All @@ -35,7 +36,6 @@ import {
type Content,
type PartListUnion,
type Tool,
type CallableTool,
} from '@google/genai';
import type { Config } from '../config/config.js';
import { MockTool } from '../test-utils/mock-tool.js';
Expand Down Expand Up @@ -508,7 +508,7 @@ describe('LocalAgentExecutor', () => {
const mockMcpTool = {
tool: vi.fn(),
callTool: vi.fn(),
} as unknown as CallableTool;
} as unknown as CallableToolWithProgress;

const mcpTool = new DiscoveredMCPTool(
mockMcpTool,
Expand Down
4 changes: 2 additions & 2 deletions packages/core/src/core/coreToolScheduler.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import { describe, it, expect, vi } from 'vitest';
import type { Mock } from 'vitest';
import type { CallableTool } from '@google/genai';
import type { CallableToolWithProgress } from '../tools/mcp-client.js';
import { CoreToolScheduler } from './coreToolScheduler.js';
import {
type ToolCall,
Expand Down Expand Up @@ -1934,7 +1934,7 @@ describe('CoreToolScheduler Sequential Execution', () => {
const serverName = 'test-server';
const toolName = 'test-tool';
const mcpTool = new DiscoveredMCPTool(
mockMcpTool as unknown as CallableTool,
mockMcpTool as unknown as CallableToolWithProgress,
serverName,
toolName,
'description',
Expand Down
6 changes: 3 additions & 3 deletions packages/core/src/core/prompts.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import {
} from '../config/models.js';
import { ApprovalMode } from '../policy/types.js';
import { DiscoveredMCPTool } from '../tools/mcp-tool.js';
import type { CallableTool } from '@google/genai';
import type { CallableToolWithProgress } from '../tools/mcp-client.js';
import type { MessageBus } from '../confirmation-bus/message-bus.js';

// Mock tool names if they are dynamically generated or complex
Expand Down Expand Up @@ -442,7 +442,7 @@ describe('Core System Prompt (prompts.ts)', () => {
vi.mocked(mockConfig.getApprovalMode).mockReturnValue(ApprovalMode.PLAN);

const readOnlyMcpTool = new DiscoveredMCPTool(
{} as CallableTool,
{} as CallableToolWithProgress,
'readonly-server',
'read_static_value',
'A read-only tool',
Expand All @@ -453,7 +453,7 @@ describe('Core System Prompt (prompts.ts)', () => {
);

const nonReadOnlyMcpTool = new DiscoveredMCPTool(
{} as CallableTool,
{} as CallableToolWithProgress,
'nonreadonly-server',
'non_read_static_value',
'A non-read-only tool',
Expand Down
Loading
Loading