mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 08:45:50 +00:00
style: 完成所有文件的lint
This commit is contained in:
@@ -1,61 +1,61 @@
|
||||
import type { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/index.mjs'
|
||||
import * as React from 'react'
|
||||
import { FileEditToolUseRejectedMessage } from 'src/components/FileEditToolUseRejectedMessage.js'
|
||||
import { MessageResponse } from 'src/components/MessageResponse.js'
|
||||
import { extractTag } from 'src/utils/messages.js'
|
||||
import { FallbackToolUseErrorMessage } from 'src/components/FallbackToolUseErrorMessage.js'
|
||||
import { FileEditToolUpdatedMessage } from 'src/components/FileEditToolUpdatedMessage.js'
|
||||
import type { ToolResultBlockParam } from '@anthropic-ai/sdk/resources/index.mjs';
|
||||
import * as React from 'react';
|
||||
import { FileEditToolUseRejectedMessage } from 'src/components/FileEditToolUseRejectedMessage.js';
|
||||
import { MessageResponse } from 'src/components/MessageResponse.js';
|
||||
import { extractTag } from 'src/utils/messages.js';
|
||||
import { FallbackToolUseErrorMessage } from 'src/components/FallbackToolUseErrorMessage.js';
|
||||
import { FileEditToolUpdatedMessage } from 'src/components/FileEditToolUpdatedMessage.js';
|
||||
|
||||
import { Text } from '@anthropic/ink'
|
||||
import { FilePathLink } from 'src/components/FilePathLink.js'
|
||||
import type { Tools } from 'src/Tool.js'
|
||||
import type { Message, ProgressMessage } from 'src/types/message.js'
|
||||
import { FILE_NOT_FOUND_CWD_NOTE, getDisplayPath } from 'src/utils/file.js'
|
||||
import { getPlansDirectory } from 'src/utils/plans.js'
|
||||
import type { ThemeName } from 'src/utils/theme.js'
|
||||
import type { FileEditOutput } from './types.js'
|
||||
import { Text } from '@anthropic/ink';
|
||||
import { FilePathLink } from 'src/components/FilePathLink.js';
|
||||
import type { Tools } from 'src/Tool.js';
|
||||
import type { Message, ProgressMessage } from 'src/types/message.js';
|
||||
import { FILE_NOT_FOUND_CWD_NOTE, getDisplayPath } from 'src/utils/file.js';
|
||||
import { getPlansDirectory } from 'src/utils/plans.js';
|
||||
import type { ThemeName } from 'src/utils/theme.js';
|
||||
import type { FileEditOutput } from './types.js';
|
||||
|
||||
export function userFacingName(
|
||||
input:
|
||||
| Partial<{
|
||||
file_path: string
|
||||
old_string: string
|
||||
new_string: string
|
||||
replace_all: boolean
|
||||
edits: unknown[]
|
||||
file_path: string;
|
||||
old_string: string;
|
||||
new_string: string;
|
||||
replace_all: boolean;
|
||||
edits: unknown[];
|
||||
}>
|
||||
| undefined,
|
||||
): string {
|
||||
if (!input) {
|
||||
return 'Update'
|
||||
return 'Update';
|
||||
}
|
||||
if (input.file_path?.startsWith(getPlansDirectory())) {
|
||||
return 'Updated plan'
|
||||
return 'Updated plan';
|
||||
}
|
||||
// Hashline edits always modify an existing file (line-ref based)
|
||||
if (input.edits != null) {
|
||||
return 'Update'
|
||||
return 'Update';
|
||||
}
|
||||
if (input.old_string === '') {
|
||||
return 'Create'
|
||||
return 'Create';
|
||||
}
|
||||
return 'Update'
|
||||
return 'Update';
|
||||
}
|
||||
|
||||
export function getToolUseSummary(
|
||||
input:
|
||||
| Partial<{
|
||||
file_path: string
|
||||
old_string: string
|
||||
new_string: string
|
||||
replace_all: boolean
|
||||
file_path: string;
|
||||
old_string: string;
|
||||
new_string: string;
|
||||
replace_all: boolean;
|
||||
}>
|
||||
| undefined,
|
||||
): string | null {
|
||||
if (!input?.file_path) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
return getDisplayPath(input.file_path)
|
||||
return getDisplayPath(input.file_path);
|
||||
}
|
||||
|
||||
export function renderToolUseMessage(
|
||||
@@ -63,17 +63,13 @@ export function renderToolUseMessage(
|
||||
{ verbose }: { verbose: boolean },
|
||||
): React.ReactNode {
|
||||
if (!file_path) {
|
||||
return null
|
||||
return null;
|
||||
}
|
||||
// For plan files, path is already in userFacingName
|
||||
if (file_path.startsWith(getPlansDirectory())) {
|
||||
return ''
|
||||
return '';
|
||||
}
|
||||
return (
|
||||
<FilePathLink filePath={file_path}>
|
||||
{verbose ? file_path : getDisplayPath(file_path)}
|
||||
</FilePathLink>
|
||||
)
|
||||
return <FilePathLink filePath={file_path}>{verbose ? file_path : getDisplayPath(file_path)}</FilePathLink>;
|
||||
}
|
||||
|
||||
export function renderToolResultMessage(
|
||||
@@ -82,7 +78,7 @@ export function renderToolResultMessage(
|
||||
{ style, verbose }: { style?: 'condensed'; verbose: boolean },
|
||||
): React.ReactNode {
|
||||
// For plan files, show /plan hint above the diff
|
||||
const isPlanFile = filePath.startsWith(getPlansDirectory())
|
||||
const isPlanFile = filePath.startsWith(getPlansDirectory());
|
||||
|
||||
return (
|
||||
<FileEditToolUpdatedMessage
|
||||
@@ -92,30 +88,30 @@ export function renderToolResultMessage(
|
||||
verbose={verbose}
|
||||
previewHint={isPlanFile ? '/plan to preview' : undefined}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToolUseRejectedMessage(
|
||||
input: {
|
||||
file_path: string
|
||||
old_string?: string
|
||||
new_string?: string
|
||||
replace_all?: boolean
|
||||
edits?: unknown[]
|
||||
file_path: string;
|
||||
old_string?: string;
|
||||
new_string?: string;
|
||||
replace_all?: boolean;
|
||||
edits?: unknown[];
|
||||
},
|
||||
_options: {
|
||||
columns: number
|
||||
messages: Message[]
|
||||
progressMessagesForMessage: ProgressMessage[]
|
||||
style?: 'condensed'
|
||||
theme: ThemeName
|
||||
tools: Tools
|
||||
verbose: boolean
|
||||
columns: number;
|
||||
messages: Message[];
|
||||
progressMessagesForMessage: ProgressMessage[];
|
||||
style?: 'condensed';
|
||||
theme: ThemeName;
|
||||
tools: Tools;
|
||||
verbose: boolean;
|
||||
},
|
||||
): React.ReactElement {
|
||||
const { style, verbose } = _options
|
||||
const filePath = input.file_path
|
||||
const isNewFile = input.old_string === ''
|
||||
const { style, verbose } = _options;
|
||||
const filePath = input.file_path;
|
||||
const isNewFile = input.old_string === '';
|
||||
|
||||
return (
|
||||
<FileEditToolUseRejectedMessage
|
||||
@@ -124,36 +120,32 @@ export function renderToolUseRejectedMessage(
|
||||
style={style}
|
||||
verbose={verbose}
|
||||
/>
|
||||
)
|
||||
);
|
||||
}
|
||||
|
||||
export function renderToolUseErrorMessage(
|
||||
result: ToolResultBlockParam['content'],
|
||||
options: {
|
||||
progressMessagesForMessage: ProgressMessage[]
|
||||
tools: Tools
|
||||
verbose: boolean
|
||||
progressMessagesForMessage: ProgressMessage[];
|
||||
tools: Tools;
|
||||
verbose: boolean;
|
||||
},
|
||||
): React.ReactElement {
|
||||
const { verbose } = options
|
||||
if (
|
||||
!verbose &&
|
||||
typeof result === 'string' &&
|
||||
extractTag(result, 'tool_use_error')
|
||||
) {
|
||||
const errorMessage = extractTag(result, 'tool_use_error')
|
||||
const { verbose } = options;
|
||||
if (!verbose && typeof result === 'string' && extractTag(result, 'tool_use_error')) {
|
||||
const errorMessage = extractTag(result, 'tool_use_error');
|
||||
if (errorMessage?.includes(FILE_NOT_FOUND_CWD_NOTE)) {
|
||||
return (
|
||||
<MessageResponse>
|
||||
<Text color="error">File not found</Text>
|
||||
</MessageResponse>
|
||||
)
|
||||
);
|
||||
}
|
||||
return (
|
||||
<MessageResponse>
|
||||
<Text color="error">Error editing file</Text>
|
||||
</MessageResponse>
|
||||
)
|
||||
);
|
||||
}
|
||||
return <FallbackToolUseErrorMessage result={result} verbose={verbose} />
|
||||
return <FallbackToolUseErrorMessage result={result} verbose={verbose} />;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user