mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 06:15:51 +00:00
feat: 添加 UI 组件增强与测试覆盖
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
23
src/components/messages/SnipBoundaryMessage.tsx
Normal file
23
src/components/messages/SnipBoundaryMessage.tsx
Normal file
@@ -0,0 +1,23 @@
|
||||
/**
|
||||
* SnipBoundaryMessage — visual separator showing where conversation was snipped.
|
||||
*/
|
||||
import * as React from 'react';
|
||||
import { Box, Text } from '@anthropic/ink';
|
||||
import type { Message } from '../../types/message.js';
|
||||
|
||||
type Props = {
|
||||
message: Message;
|
||||
};
|
||||
|
||||
export function SnipBoundaryMessage({ message }: Props): React.ReactNode {
|
||||
const content =
|
||||
typeof (message as Record<string, unknown>).content === 'string'
|
||||
? ((message as Record<string, unknown>).content as string)
|
||||
: '[snip] Conversation history before this point has been snipped.';
|
||||
|
||||
return (
|
||||
<Box marginTop={1} marginBottom={1}>
|
||||
<Text dimColor>── {content} ──</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
31
src/components/messages/UserCrossSessionMessage.tsx
Normal file
31
src/components/messages/UserCrossSessionMessage.tsx
Normal file
@@ -0,0 +1,31 @@
|
||||
/**
|
||||
* UserCrossSessionMessage — render a message received from another Claude session
|
||||
* via UDS_INBOX (SendMessage tool).
|
||||
*/
|
||||
import type { TextBlockParam } from '@anthropic-ai/sdk/resources/index.mjs';
|
||||
import * as React from 'react';
|
||||
import { Box, Text } from '@anthropic/ink';
|
||||
import { extractTag } from '../../utils/messages.js';
|
||||
|
||||
type Props = {
|
||||
addMargin: boolean;
|
||||
param: TextBlockParam;
|
||||
};
|
||||
|
||||
export function UserCrossSessionMessage({ param, addMargin }: Props): React.ReactNode {
|
||||
const text = param.text;
|
||||
const extracted = extractTag(text, 'cross-session-message');
|
||||
if (!extracted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const fromMatch = text.match(/from="([^"]*)"/);
|
||||
const from = fromMatch?.[1] ?? 'another session';
|
||||
|
||||
return (
|
||||
<Box flexDirection="row" marginTop={addMargin ? 1 : 0}>
|
||||
<Text dimColor>[{from}] </Text>
|
||||
<Text>{extracted}</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
30
src/components/messages/UserForkBoilerplateMessage.tsx
Normal file
30
src/components/messages/UserForkBoilerplateMessage.tsx
Normal file
@@ -0,0 +1,30 @@
|
||||
/**
|
||||
* UserForkBoilerplateMessage — render the fork/subagent boilerplate directive.
|
||||
*/
|
||||
import type { TextBlockParam } from '@anthropic-ai/sdk/resources/index.mjs';
|
||||
import * as React from 'react';
|
||||
import { Box, Text } from '@anthropic/ink';
|
||||
import { extractTag } from '../../utils/messages.js';
|
||||
|
||||
type Props = {
|
||||
addMargin: boolean;
|
||||
param: TextBlockParam;
|
||||
};
|
||||
|
||||
export function UserForkBoilerplateMessage({ param, addMargin }: Props): React.ReactNode {
|
||||
const text = param.text;
|
||||
const extracted = extractTag(text, 'fork-boilerplate');
|
||||
if (!extracted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const firstLine = extracted.trim().split('\n')[0] ?? '';
|
||||
const preview = firstLine.length > 80 ? firstLine.slice(0, 77) + '...' : firstLine;
|
||||
|
||||
return (
|
||||
<Box flexDirection="row" marginTop={addMargin ? 1 : 0}>
|
||||
<Text dimColor>[fork] </Text>
|
||||
<Text>{preview}</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
36
src/components/messages/UserGitHubWebhookMessage.tsx
Normal file
36
src/components/messages/UserGitHubWebhookMessage.tsx
Normal file
@@ -0,0 +1,36 @@
|
||||
/**
|
||||
* UserGitHubWebhookMessage — render inbound GitHub webhook activity.
|
||||
*/
|
||||
import type { TextBlockParam } from '@anthropic-ai/sdk/resources/index.mjs';
|
||||
import * as React from 'react';
|
||||
import { Box, Text } from '@anthropic/ink';
|
||||
import { extractTag } from '../../utils/messages.js';
|
||||
|
||||
type Props = {
|
||||
addMargin: boolean;
|
||||
param: TextBlockParam;
|
||||
};
|
||||
|
||||
export function UserGitHubWebhookMessage({ param, addMargin }: Props): React.ReactNode {
|
||||
const text = param.text;
|
||||
const extracted = extractTag(text, 'github-webhook-activity');
|
||||
if (!extracted) {
|
||||
return null;
|
||||
}
|
||||
|
||||
const eventMatch = extracted.match(/event[_-]?type[":\s]+["']?(\w+)/);
|
||||
const repoMatch = extracted.match(/repo(?:sitory)?[":\s]+["']?([^"'\s,}]+)/);
|
||||
const event = eventMatch?.[1] ?? 'activity';
|
||||
const repo = repoMatch?.[1] ?? '';
|
||||
const repoSuffix = repo ? ` in ${repo}` : '';
|
||||
|
||||
return (
|
||||
<Box flexDirection="row" marginTop={addMargin ? 1 : 0}>
|
||||
<Text dimColor>[GitHub] </Text>
|
||||
<Text>
|
||||
{event}
|
||||
{repoSuffix}
|
||||
</Text>
|
||||
</Box>
|
||||
);
|
||||
}
|
||||
Reference in New Issue
Block a user