-
Notifications
You must be signed in to change notification settings - Fork 3k
fix(cli): wrap long compact tool summaries #6847
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
e930217
08bbf1a
dca6849
e304014
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -6,20 +6,30 @@ | |
|
|
||
| import type React from 'react'; | ||
| import { Box, Text } from 'ink'; | ||
| import stringWidth from 'string-width'; | ||
| import wrapAnsi from 'wrap-ansi'; | ||
| import type { IndividualToolCallDisplay } from '../../types.js'; | ||
| import { ToolCallStatus } from '../../types.js'; | ||
| import type { AnsiOutputDisplay } from '@qwen-code/qwen-code-core'; | ||
| import { ToolDisplayNames } from '@qwen-code/qwen-code-core'; | ||
| import { t } from '../../../i18n/index.js'; | ||
| import { SHELL_COMMAND_NAME } from '../../constants.js'; | ||
| import { ToolStatusIndicator } from '../shared/ToolStatusIndicator.js'; | ||
| import { | ||
| STATUS_INDICATOR_WIDTH, | ||
| ToolStatusIndicator, | ||
| } from '../shared/ToolStatusIndicator.js'; | ||
| import { ToolElapsedTime } from '../shared/ToolElapsedTime.js'; | ||
| import { formatDuration } from '../../utils/formatters.js'; | ||
|
|
||
| interface CompactToolGroupDisplayProps { | ||
| toolCalls: IndividualToolCallDisplay[]; | ||
| contentWidth: number; | ||
| } | ||
|
|
||
| const COMPACT_GROUP_HORIZONTAL_PADDING = 2; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] — qwen3.7-max via Qwen Code /review |
||
| const ELAPSED_TIME_MARGIN_LEFT = 1; | ||
| const EXECUTING_ELAPSED_TIME_RESERVED_LABEL = '99h 59m 59s'; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] — qwen3.7-max via Qwen Code /review |
||
|
|
||
| // Priority: Confirming > Executing > Error > Canceled > Pending > Success | ||
| export function getOverallStatus( | ||
| toolCalls: IndividualToolCallDisplay[], | ||
|
|
@@ -62,6 +72,32 @@ function getShellTimeoutMs( | |
| return undefined; | ||
| } | ||
|
|
||
| function isToolGroupActive(status: ToolCallStatus): boolean { | ||
| return ( | ||
| status === ToolCallStatus.Executing || | ||
| status === ToolCallStatus.Pending || | ||
| status === ToolCallStatus.Confirming | ||
| ); | ||
| } | ||
|
|
||
| function getElapsedTimeReservedWidth( | ||
| tool: IndividualToolCallDisplay, | ||
| status: ToolCallStatus, | ||
| ): number { | ||
| if (status !== ToolCallStatus.Executing) return 0; | ||
|
|
||
| const timeoutMs = getShellTimeoutMs(tool); | ||
| let label = EXECUTING_ELAPSED_TIME_RESERVED_LABEL; | ||
| if (timeoutMs != null && timeoutMs > 0) { | ||
| const maxElapsedStr = formatDuration(timeoutMs, { | ||
| hideTrailingZeros: true, | ||
| }); | ||
| label = `(${maxElapsedStr} · timeout ${maxElapsedStr})`; | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. [Suggestion] The timeout label format — qwen3.7-max via Qwen Code /review |
||
| } | ||
|
|
||
| return ELAPSED_TIME_MARGIN_LEFT + stringWidth(label); | ||
| } | ||
|
|
||
| type ToolCategory = | ||
| | 'read' | ||
| | 'edit' | ||
|
|
@@ -312,24 +348,46 @@ export function buildToolSummary( | |
| return parts.join(', '); | ||
| } | ||
|
|
||
| export function estimateCompactToolGroupHeight( | ||
| toolCalls: IndividualToolCallDisplay[], | ||
| contentWidth: number, | ||
| ): number { | ||
| if (toolCalls.length === 0) return 0; | ||
|
|
||
| const overallStatus = getOverallStatus(toolCalls); | ||
| const activeTool = getActiveTool(toolCalls); | ||
| const isActive = isToolGroupActive(overallStatus); | ||
| const summary = `${buildToolSummary(toolCalls, isActive)}${isActive ? '…' : ''}`; | ||
| const summaryWidth = Math.max( | ||
| 1, | ||
| contentWidth - | ||
| COMPACT_GROUP_HORIZONTAL_PADDING - | ||
| STATUS_INDICATOR_WIDTH - | ||
| getElapsedTimeReservedWidth(activeTool, overallStatus), | ||
| ); | ||
| const wrappedSummary = wrapAnsi(summary, summaryWidth, { | ||
| hard: true, | ||
| trim: false, | ||
| }); | ||
|
|
||
| return Math.max(1, wrappedSummary.split('\n').length); | ||
| } | ||
|
|
||
| export const CompactToolGroupDisplay: React.FC< | ||
| CompactToolGroupDisplayProps | ||
| > = ({ toolCalls, contentWidth }) => { | ||
| if (toolCalls.length === 0) return null; | ||
|
|
||
| const overallStatus = getOverallStatus(toolCalls); | ||
| const activeTool = getActiveTool(toolCalls); | ||
| const isActive = | ||
| overallStatus === ToolCallStatus.Executing || | ||
| overallStatus === ToolCallStatus.Pending || | ||
| overallStatus === ToolCallStatus.Confirming; | ||
| const isActive = isToolGroupActive(overallStatus); | ||
|
|
||
| return ( | ||
| <Box flexDirection="column" width={contentWidth} paddingX={1} gap={0}> | ||
| <Box flexDirection="row"> | ||
| <ToolStatusIndicator status={overallStatus} name={activeTool.name} /> | ||
| <Box flexGrow={1}> | ||
| <Text wrap="truncate-end" bold> | ||
| <Text wrap="wrap" bold> | ||
|
han-dreamer marked this conversation as resolved.
|
||
| {buildToolSummary(toolCalls, isActive)} | ||
| {isActive && <Text key="ellipsis">…</Text>} | ||
| </Text> | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.