mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-18 14:25:51 +00:00
更新大量 tsx 原始文件; 已经迁移 login panel; 部分 (#121)
* style(B1-1): 格式化 ink/buddy/cli/context/screens/tasks/services/keybindings/state (43 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 修复了 Box.tsx 和 ScrollBox.tsx 中无效的 global.d.ts import。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-2): 格式化 commands (79 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-3): 格式化 components/messages,permissions,mcp,sandbox,shell (104 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-4): 格式化 components/PromptInput,FeedbackSurvey,tasks,agents,skills,design-system,wizard (73 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-5): 格式化 components其余 + hooks + tools (232 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * style(B1-6): 格式化 main/entrypoints/utils/moreright (21 files) 纯格式化:移除分号、React Compiler import、import 多行展开。 Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * docs: 更新 README,新增 Run.ps1/TODO.md,删除 V6.md - README.md: 大幅重写,更详细版本历史和配置示例 - Run.ps1: 新增 Windows 启动脚本 - TODO.md: 新增包完成清单 - V6.md: 删除(架构重构规划已不适用) Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com> * fix: 修复以前的问题 * fix: 修复 login 面板的问题 --------- Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,106 +1,98 @@
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
import * as React from 'react';
|
||||
import { useMemo } from 'react';
|
||||
import { useTerminalSize } from '../../hooks/useTerminalSize.js';
|
||||
import { Ansi, Text } from '../../ink.js';
|
||||
import { createHyperlink } from '../../utils/hyperlink.js';
|
||||
import { jsonParse, jsonStringify } from '../../utils/slowOperations.js';
|
||||
import { renderTruncatedContent } from '../../utils/terminal.js';
|
||||
import { MessageResponse } from '../MessageResponse.js';
|
||||
import { InVirtualListContext } from '../messageActions.js';
|
||||
import { useExpandShellOutput } from './ExpandShellOutputContext.js';
|
||||
import * as React from 'react'
|
||||
import { useMemo } from 'react'
|
||||
import { useTerminalSize } from '../../hooks/useTerminalSize.js'
|
||||
import { Ansi, Text } from '../../ink.js'
|
||||
import { createHyperlink } from '../../utils/hyperlink.js'
|
||||
import { jsonParse, jsonStringify } from '../../utils/slowOperations.js'
|
||||
import { renderTruncatedContent } from '../../utils/terminal.js'
|
||||
import { MessageResponse } from '../MessageResponse.js'
|
||||
import { InVirtualListContext } from '../messageActions.js'
|
||||
import { useExpandShellOutput } from './ExpandShellOutputContext.js'
|
||||
|
||||
export function tryFormatJson(line: string): string {
|
||||
try {
|
||||
const parsed = jsonParse(line);
|
||||
const stringified = jsonStringify(parsed);
|
||||
const parsed = jsonParse(line)
|
||||
const stringified = jsonStringify(parsed)
|
||||
|
||||
// Check if precision was lost during JSON round-trip
|
||||
// This happens when large integers exceed Number.MAX_SAFE_INTEGER
|
||||
// We normalize both strings by removing whitespace and unnecessary
|
||||
// escapes (\/ is valid but optional in JSON) for comparison
|
||||
const normalizedOriginal = line.replace(/\\\//g, '/').replace(/\s+/g, '');
|
||||
const normalizedStringified = stringified.replace(/\s+/g, '');
|
||||
const normalizedOriginal = line.replace(/\\\//g, '/').replace(/\s+/g, '')
|
||||
const normalizedStringified = stringified.replace(/\s+/g, '')
|
||||
|
||||
if (normalizedOriginal !== normalizedStringified) {
|
||||
// Precision loss detected - return original line unformatted
|
||||
return line;
|
||||
return line
|
||||
}
|
||||
return jsonStringify(parsed, null, 2);
|
||||
|
||||
return jsonStringify(parsed, null, 2)
|
||||
} catch {
|
||||
return line;
|
||||
return line
|
||||
}
|
||||
}
|
||||
const MAX_JSON_FORMAT_LENGTH = 10_000;
|
||||
|
||||
const MAX_JSON_FORMAT_LENGTH = 10_000
|
||||
|
||||
export function tryJsonFormatContent(content: string): string {
|
||||
if (content.length > MAX_JSON_FORMAT_LENGTH) {
|
||||
return content;
|
||||
return content
|
||||
}
|
||||
const allLines = content.split('\n');
|
||||
return allLines.map(tryFormatJson).join('\n');
|
||||
const allLines = content.split('\n')
|
||||
return allLines.map(tryFormatJson).join('\n')
|
||||
}
|
||||
|
||||
// Match http(s) URLs inside JSON string values. Conservative: no quotes,
|
||||
// no whitespace, no trailing comma/brace that'd be JSON structure.
|
||||
const URL_IN_JSON = /https?:\/\/[^\s"'<>\\]+/g;
|
||||
const URL_IN_JSON = /https?:\/\/[^\s"'<>\\]+/g
|
||||
|
||||
export function linkifyUrlsInText(content: string): string {
|
||||
return content.replace(URL_IN_JSON, url => createHyperlink(url));
|
||||
return content.replace(URL_IN_JSON, url => createHyperlink(url))
|
||||
}
|
||||
export function OutputLine(t0) {
|
||||
const $ = _c(11);
|
||||
const {
|
||||
content,
|
||||
verbose,
|
||||
isError,
|
||||
isWarning,
|
||||
linkifyUrls
|
||||
} = t0;
|
||||
const {
|
||||
columns
|
||||
} = useTerminalSize();
|
||||
const expandShellOutput = useExpandShellOutput();
|
||||
const inVirtualList = React.useContext(InVirtualListContext);
|
||||
const shouldShowFull = verbose || expandShellOutput;
|
||||
let t1;
|
||||
if ($[0] !== columns || $[1] !== content || $[2] !== inVirtualList || $[3] !== linkifyUrls || $[4] !== shouldShowFull) {
|
||||
bb0: {
|
||||
let formatted = tryJsonFormatContent(content);
|
||||
if (linkifyUrls) {
|
||||
formatted = linkifyUrlsInText(formatted);
|
||||
}
|
||||
if (shouldShowFull) {
|
||||
t1 = stripUnderlineAnsi(formatted);
|
||||
break bb0;
|
||||
}
|
||||
t1 = stripUnderlineAnsi(renderTruncatedContent(formatted, columns, inVirtualList));
|
||||
|
||||
export function OutputLine({
|
||||
content,
|
||||
verbose,
|
||||
isError,
|
||||
isWarning,
|
||||
linkifyUrls,
|
||||
}: {
|
||||
content: string
|
||||
verbose: boolean
|
||||
isError?: boolean
|
||||
isWarning?: boolean
|
||||
linkifyUrls?: boolean
|
||||
}): React.ReactNode {
|
||||
const { columns } = useTerminalSize()
|
||||
// Context-based expansion for latest user shell output (from ! commands)
|
||||
const expandShellOutput = useExpandShellOutput()
|
||||
const inVirtualList = React.useContext(InVirtualListContext)
|
||||
|
||||
// Show full output if verbose mode OR if this is the latest user shell output
|
||||
const shouldShowFull = verbose || expandShellOutput
|
||||
|
||||
const formattedContent = useMemo(() => {
|
||||
let formatted = tryJsonFormatContent(content)
|
||||
if (linkifyUrls) {
|
||||
formatted = linkifyUrlsInText(formatted)
|
||||
}
|
||||
$[0] = columns;
|
||||
$[1] = content;
|
||||
$[2] = inVirtualList;
|
||||
$[3] = linkifyUrls;
|
||||
$[4] = shouldShowFull;
|
||||
$[5] = t1;
|
||||
} else {
|
||||
t1 = $[5];
|
||||
}
|
||||
const formattedContent = t1;
|
||||
const color = isError ? "error" : isWarning ? "warning" : undefined;
|
||||
let t2;
|
||||
if ($[6] !== formattedContent) {
|
||||
t2 = <Ansi>{formattedContent}</Ansi>;
|
||||
$[6] = formattedContent;
|
||||
$[7] = t2;
|
||||
} else {
|
||||
t2 = $[7];
|
||||
}
|
||||
let t3;
|
||||
if ($[8] !== color || $[9] !== t2) {
|
||||
t3 = <MessageResponse><Text color={color}>{t2}</Text></MessageResponse>;
|
||||
$[8] = color;
|
||||
$[9] = t2;
|
||||
$[10] = t3;
|
||||
} else {
|
||||
t3 = $[10];
|
||||
}
|
||||
return t3;
|
||||
if (shouldShowFull) {
|
||||
return stripUnderlineAnsi(formatted)
|
||||
}
|
||||
return stripUnderlineAnsi(
|
||||
renderTruncatedContent(formatted, columns, inVirtualList),
|
||||
)
|
||||
}, [content, shouldShowFull, columns, linkifyUrls, inVirtualList])
|
||||
|
||||
const color = isError ? 'error' : isWarning ? 'warning' : undefined
|
||||
|
||||
return (
|
||||
<MessageResponse>
|
||||
<Text color={color}>
|
||||
<Ansi>{formattedContent}</Ansi>
|
||||
</Text>
|
||||
</MessageResponse>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,6 +104,8 @@ export function OutputLine(t0) {
|
||||
*/
|
||||
export function stripUnderlineAnsi(content: string): string {
|
||||
return content.replace(
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/\u001b\[([0-9]+;)*4(;[0-9]+)*m|\u001b\[4(;[0-9]+)*m|\u001b\[([0-9]+;)*4m/g, '');
|
||||
// eslint-disable-next-line no-control-regex
|
||||
/\u001b\[([0-9]+;)*4(;[0-9]+)*m|\u001b\[4(;[0-9]+)*m|\u001b\[([0-9]+;)*4m/g,
|
||||
'',
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user