claude-code-best/src/components/CompactSummary.tsx
claude-code-best 6ff839d625 fix: 优化压缩错误消息和自动压缩提示的可理解性
- "Not enough messages" 添加 "Send a few more messages first" 引导
- "Conversation too long" 提示从模糊的 "Press esc twice" 改为建议 /compact 或 /clear
- 自动压缩标题从 "Compact summary" 改为 "Conversation summarized to free up context"
- 快捷键提示从 "expand" 改为 "view summary"
- 新增 7 个测试覆盖压缩相关消息

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
2026-05-05 07:19:19 +08:00

106 lines
3.3 KiB
TypeScript

import * as React from 'react';
import { BLACK_CIRCLE } from '../constants/figures.js';
import { Box, Text } from '@anthropic/ink';
import type { Screen } from '../screens/REPL.js';
import type { NormalizedUserMessage } from '../types/message.js';
import { getUserMessageText } from '../utils/messages.js';
import { ConfigurableShortcutHint } from './ConfigurableShortcutHint.js';
import { MessageResponse } from './MessageResponse.js';
type Props = {
message: NormalizedUserMessage;
screen: Screen;
};
export function CompactSummary({ message, screen }: Props): React.ReactNode {
const isTranscriptMode = screen === 'transcript';
const textContent = getUserMessageText(message) || '';
const metadata = message.summarizeMetadata as
| {
messagesSummarized?: number;
direction?: string;
userContext?: string;
}
| undefined;
// "Summarize from here" with metadata
if (metadata) {
return (
<Box flexDirection="column" marginTop={1}>
<Box flexDirection="row">
<Box minWidth={2}>
<Text color="text">{BLACK_CIRCLE}</Text>
</Box>
<Box flexDirection="column">
<Text bold>Summarized conversation</Text>
{!isTranscriptMode && (
<MessageResponse>
<Box flexDirection="column">
<Text dimColor>
Summarized {metadata.messagesSummarized} messages{' '}
{metadata.direction === 'up_to' ? 'up to this point' : 'from this point'}
</Text>
{metadata.userContext && (
<Text dimColor>
Context: {'\u201c'}
{metadata.userContext}
{'\u201d'}
</Text>
)}
<Text dimColor>
<ConfigurableShortcutHint
action="app:toggleTranscript"
context="Global"
fallback="ctrl+o"
description="expand history"
parens
/>
</Text>
</Box>
</MessageResponse>
)}
{isTranscriptMode && (
<MessageResponse>
<Text>{textContent}</Text>
</MessageResponse>
)}
</Box>
</Box>
</Box>
);
}
// Default compact summary (auto-compact)
return (
<Box flexDirection="column" marginTop={1}>
<Box flexDirection="row">
<Box minWidth={2}>
<Text color="text">{BLACK_CIRCLE}</Text>
</Box>
<Box flexDirection="column">
<Text bold>
Conversation summarized to free up context
{!isTranscriptMode && (
<Text dimColor>
{' '}
<ConfigurableShortcutHint
action="app:toggleTranscript"
context="Global"
fallback="ctrl+o"
description="view summary"
parens
/>
</Text>
)}
</Text>
</Box>
</Box>
{isTranscriptMode && (
<MessageResponse>
<Text>{textContent}</Text>
</MessageResponse>
)}
</Box>
);
}