mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 08:45:50 +00:00
feat: 工具层及 mcp 大重构 (#252)
* feat: 第一版大重构 * fix: 修复类型问题 * chore: 更新版本到 1.3.2 * Add brave as alternative WebSearchTool * fix: 修正顺序 * fix: 修复对穷鬼模式的 auto dream 和 session memory 越过 * feat: 穷鬼模式去除 session-summary * feat: 创建 builtin-tools 包,搬运所有工具实现 将 src/tools/ 下的全部 60 个工具目录迁移至 packages/builtin-tools/src/tools/, 内部导入路径已更新为 src/ alias 模式。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: 更新 src/ 中所有工具引用至 builtin-tools 包,删除 src/tools/ - src/tools.ts 及 178 个 src/ 文件的 import 路径从 ./tools/ 改为 builtin-tools/tools/ - 删除 src/tools/ 整个目录(已迁移至 packages/builtin-tools/) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * chore: 添加 builtin-tools 路径别名至 tsconfig,更新 bun.lock - tsconfig.json 新增 builtin-tools/* 和 builtin-tools 路径映射 - 新增 packages/builtin-tools/src 至 include Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * refactor: 为 builtin-tools、mcp-client、agent-tools 添加 @claude-code-best 作用域前缀 所有包名及 import 路径统一添加 @claude-code-best/ 前缀: - builtin-tools → @claude-code-best/builtin-tools - mcp-client → @claude-code-best/mcp-client - agent-tools → @claude-code-best/agent-tools Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 修复 node 环境没有 bun 的问题 --------- Co-authored-by: Eric-Guo <eric.guocz@gmail.com> Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
181
packages/builtin-tools/src/tools/SkillTool/UI.tsx
Normal file
181
packages/builtin-tools/src/tools/SkillTool/UI.tsx
Normal file
@@ -0,0 +1,181 @@
|
||||
import type { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
|
||||
import * as React from 'react'
|
||||
import { SubAgentProvider } from 'src/components/CtrlOToExpand.js'
|
||||
import { FallbackToolUseErrorMessage } from 'src/components/FallbackToolUseErrorMessage.js'
|
||||
import { FallbackToolUseRejectedMessage } from 'src/components/FallbackToolUseRejectedMessage.js'
|
||||
import type { z } from 'zod/v4'
|
||||
import type { Command } from 'src/commands.js'
|
||||
import { Byline } from '@anthropic/ink'
|
||||
import { Message as MessageComponent } from 'src/components/Message.js'
|
||||
import { MessageResponse } from 'src/components/MessageResponse.js'
|
||||
import { Box, Text } from '@anthropic/ink'
|
||||
import type { Tools } from 'src/Tool.js'
|
||||
import type { ProgressMessage } from 'src/types/message.js'
|
||||
import { buildSubagentLookups, EMPTY_LOOKUPS } from 'src/utils/messages.js'
|
||||
import { plural } from 'src/utils/stringUtils.js'
|
||||
import type { inputSchema, Output, Progress } from './SkillTool.js'
|
||||
|
||||
type Input = z.infer<ReturnType<typeof inputSchema>>
|
||||
|
||||
const MAX_PROGRESS_MESSAGES_TO_SHOW = 3
|
||||
const INITIALIZING_TEXT = 'Initializing…'
|
||||
|
||||
export function renderToolResultMessage(output: Output): React.ReactNode {
|
||||
// Handle forked skill result
|
||||
if ('status' in output && output.status === 'forked') {
|
||||
return (
|
||||
<MessageResponse height={1}>
|
||||
<Text>
|
||||
<Byline>{['Done']}</Byline>
|
||||
</Text>
|
||||
</MessageResponse>
|
||||
)
|
||||
}
|
||||
|
||||
const parts: string[] = ['Successfully loaded skill']
|
||||
|
||||
// Show tools count (only for inline skills)
|
||||
if (
|
||||
'allowedTools' in output &&
|
||||
output.allowedTools &&
|
||||
output.allowedTools.length > 0
|
||||
) {
|
||||
const count = output.allowedTools.length
|
||||
parts.push(`${count} ${plural(count, 'tool')} allowed`)
|
||||
}
|
||||
|
||||
// Show model if non-default (only for inline skills)
|
||||
if ('model' in output && output.model) {
|
||||
parts.push(output.model)
|
||||
}
|
||||
|
||||
return (
|
||||
<MessageResponse height={1}>
|
||||
<Text>
|
||||
<Byline>{parts}</Byline>
|
||||
</Text>
|
||||
</MessageResponse>
|
||||
)
|
||||
}
|
||||
|
||||
export function renderToolUseMessage(
|
||||
{ skill }: Partial<Input>,
|
||||
{ commands }: { commands?: Command[] },
|
||||
): React.ReactNode {
|
||||
if (!skill) {
|
||||
return null
|
||||
}
|
||||
// Look up the command to check if it came from the legacy /commands folder
|
||||
const command = commands?.find(c => c.name === skill)
|
||||
const displayName =
|
||||
command?.loadedFrom === 'commands_DEPRECATED' ? `/${skill}` : skill
|
||||
return displayName
|
||||
}
|
||||
|
||||
export function renderToolUseProgressMessage(
|
||||
progressMessages: ProgressMessage<Progress>[],
|
||||
{
|
||||
tools,
|
||||
verbose,
|
||||
}: {
|
||||
tools: Tools
|
||||
verbose: boolean
|
||||
},
|
||||
): React.ReactNode {
|
||||
if (!progressMessages.length) {
|
||||
return (
|
||||
<MessageResponse height={1}>
|
||||
<Text dimColor>{INITIALIZING_TEXT}</Text>
|
||||
</MessageResponse>
|
||||
)
|
||||
}
|
||||
|
||||
// Take only the last few messages for display in non-verbose mode
|
||||
const displayedMessages = verbose
|
||||
? progressMessages
|
||||
: progressMessages.slice(-MAX_PROGRESS_MESSAGES_TO_SHOW)
|
||||
|
||||
const hiddenCount = progressMessages.length - displayedMessages.length
|
||||
const { inProgressToolUseIDs } = buildSubagentLookups(
|
||||
progressMessages.map(pm => pm.data),
|
||||
)
|
||||
|
||||
return (
|
||||
<MessageResponse>
|
||||
<Box flexDirection="column">
|
||||
<SubAgentProvider>
|
||||
{displayedMessages.map(progressMessage => (
|
||||
<Box key={progressMessage.uuid} height={1} overflow="hidden">
|
||||
<MessageComponent
|
||||
message={progressMessage.data.message}
|
||||
lookups={EMPTY_LOOKUPS}
|
||||
addMargin={false}
|
||||
tools={tools}
|
||||
commands={[]}
|
||||
verbose={verbose}
|
||||
inProgressToolUseIDs={inProgressToolUseIDs}
|
||||
progressMessagesForMessage={[]}
|
||||
shouldAnimate={false}
|
||||
shouldShowDot={false}
|
||||
style="condensed"
|
||||
isTranscriptMode={false}
|
||||
isStatic={true}
|
||||
/>
|
||||
</Box>
|
||||
))}
|
||||
</SubAgentProvider>
|
||||
{hiddenCount > 0 && (
|
||||
<Text dimColor>
|
||||
+{hiddenCount} more tool {plural(hiddenCount, 'use')}
|
||||
</Text>
|
||||
)}
|
||||
</Box>
|
||||
</MessageResponse>
|
||||
)
|
||||
}
|
||||
|
||||
export function renderToolUseRejectedMessage(
|
||||
_input: Input,
|
||||
{
|
||||
progressMessagesForMessage,
|
||||
tools,
|
||||
verbose,
|
||||
}: {
|
||||
progressMessagesForMessage: ProgressMessage<Progress>[]
|
||||
tools: Tools
|
||||
verbose: boolean
|
||||
},
|
||||
): React.ReactNode {
|
||||
return (
|
||||
<>
|
||||
{renderToolUseProgressMessage(progressMessagesForMessage, {
|
||||
tools,
|
||||
verbose,
|
||||
})}
|
||||
<FallbackToolUseRejectedMessage />
|
||||
</>
|
||||
)
|
||||
}
|
||||
|
||||
export function renderToolUseErrorMessage(
|
||||
result: ToolResultBlockParam['content'],
|
||||
{
|
||||
progressMessagesForMessage,
|
||||
tools,
|
||||
verbose,
|
||||
}: {
|
||||
progressMessagesForMessage: ProgressMessage<Progress>[]
|
||||
tools: Tools
|
||||
verbose: boolean
|
||||
},
|
||||
): React.ReactNode {
|
||||
return (
|
||||
<>
|
||||
{renderToolUseProgressMessage(progressMessagesForMessage, {
|
||||
tools,
|
||||
verbose,
|
||||
})}
|
||||
<FallbackToolUseErrorMessage result={result} verbose={verbose} />
|
||||
</>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user