mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-23 00:35: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,87 +1,93 @@
|
||||
import { c as _c } from "react/compiler-runtime";
|
||||
import React, { Suspense, use, useState } from 'react';
|
||||
import { Box, Text } from '../../ink.js';
|
||||
import { useKeybinding } from '../../keybindings/useKeybinding.js';
|
||||
import { logEvent } from '../../services/analytics/index.js';
|
||||
import type { Message } from '../../types/message.js';
|
||||
import { generatePermissionExplanation, isPermissionExplainerEnabled, type PermissionExplanation as PermissionExplanationType, type RiskLevel } from '../../utils/permissions/permissionExplainer.js';
|
||||
import { ShimmerChar } from '../Spinner/ShimmerChar.js';
|
||||
import { useShimmerAnimation } from '../Spinner/useShimmerAnimation.js';
|
||||
const LOADING_MESSAGE = 'Loading explanation…';
|
||||
function ShimmerLoadingText() {
|
||||
const $ = _c(7);
|
||||
const [ref, glimmerIndex] = useShimmerAnimation("responding", LOADING_MESSAGE, false);
|
||||
let t0;
|
||||
if ($[0] !== glimmerIndex) {
|
||||
t0 = LOADING_MESSAGE.split("").map((char, index) => <ShimmerChar key={index} char={char} index={index} glimmerIndex={glimmerIndex} messageColor="inactive" shimmerColor="text" />);
|
||||
$[0] = glimmerIndex;
|
||||
$[1] = t0;
|
||||
} else {
|
||||
t0 = $[1];
|
||||
}
|
||||
let t1;
|
||||
if ($[2] !== t0) {
|
||||
t1 = <Text>{t0}</Text>;
|
||||
$[2] = t0;
|
||||
$[3] = t1;
|
||||
} else {
|
||||
t1 = $[3];
|
||||
}
|
||||
let t2;
|
||||
if ($[4] !== ref || $[5] !== t1) {
|
||||
t2 = <Box ref={ref}>{t1}</Box>;
|
||||
$[4] = ref;
|
||||
$[5] = t1;
|
||||
$[6] = t2;
|
||||
} else {
|
||||
t2 = $[6];
|
||||
}
|
||||
return t2;
|
||||
import React, { Suspense, use, useState } from 'react'
|
||||
import { Box, Text } from '../../ink.js'
|
||||
import { useKeybinding } from '../../keybindings/useKeybinding.js'
|
||||
import { logEvent } from '../../services/analytics/index.js'
|
||||
import type { Message } from '../../types/message.js'
|
||||
import {
|
||||
generatePermissionExplanation,
|
||||
isPermissionExplainerEnabled,
|
||||
type PermissionExplanation as PermissionExplanationType,
|
||||
type RiskLevel,
|
||||
} from '../../utils/permissions/permissionExplainer.js'
|
||||
import { ShimmerChar } from '../Spinner/ShimmerChar.js'
|
||||
import { useShimmerAnimation } from '../Spinner/useShimmerAnimation.js'
|
||||
|
||||
const LOADING_MESSAGE = 'Loading explanation…'
|
||||
|
||||
function ShimmerLoadingText(): React.ReactNode {
|
||||
const [ref, glimmerIndex] = useShimmerAnimation(
|
||||
'responding',
|
||||
LOADING_MESSAGE,
|
||||
false,
|
||||
)
|
||||
|
||||
return (
|
||||
<Box ref={ref}>
|
||||
<Text>
|
||||
{LOADING_MESSAGE.split('').map((char, index) => (
|
||||
<ShimmerChar
|
||||
key={index}
|
||||
char={char}
|
||||
index={index}
|
||||
glimmerIndex={glimmerIndex}
|
||||
messageColor="inactive"
|
||||
shimmerColor="text"
|
||||
/>
|
||||
))}
|
||||
</Text>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
function getRiskColor(riskLevel: RiskLevel): 'success' | 'warning' | 'error' {
|
||||
switch (riskLevel) {
|
||||
case 'LOW':
|
||||
return 'success';
|
||||
return 'success'
|
||||
case 'MEDIUM':
|
||||
return 'warning';
|
||||
return 'warning'
|
||||
case 'HIGH':
|
||||
return 'error';
|
||||
return 'error'
|
||||
}
|
||||
}
|
||||
|
||||
function getRiskLabel(riskLevel: RiskLevel): string {
|
||||
switch (riskLevel) {
|
||||
case 'LOW':
|
||||
return 'Low risk';
|
||||
return 'Low risk'
|
||||
case 'MEDIUM':
|
||||
return 'Med risk';
|
||||
return 'Med risk'
|
||||
case 'HIGH':
|
||||
return 'High risk';
|
||||
return 'High risk'
|
||||
}
|
||||
}
|
||||
|
||||
type PermissionExplanationProps = {
|
||||
toolName: string;
|
||||
toolInput: unknown;
|
||||
toolDescription?: string;
|
||||
messages?: Message[];
|
||||
};
|
||||
toolName: string
|
||||
toolInput: unknown
|
||||
toolDescription?: string
|
||||
messages?: Message[]
|
||||
}
|
||||
|
||||
type ExplainerState = {
|
||||
visible: boolean;
|
||||
enabled: boolean;
|
||||
promise: Promise<PermissionExplanationType | null> | null;
|
||||
};
|
||||
visible: boolean
|
||||
enabled: boolean
|
||||
promise: Promise<PermissionExplanationType | null> | null
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates an explanation promise that never rejects.
|
||||
* Errors are caught and returned as null.
|
||||
*/
|
||||
function createExplanationPromise(props: PermissionExplanationProps): Promise<PermissionExplanationType | null> {
|
||||
function createExplanationPromise(
|
||||
props: PermissionExplanationProps,
|
||||
): Promise<PermissionExplanationType | null> {
|
||||
return generatePermissionExplanation({
|
||||
toolName: props.toolName,
|
||||
toolInput: props.toolInput,
|
||||
toolDescription: props.toolDescription,
|
||||
messages: props.messages,
|
||||
signal: new AbortController().signal // Won't abort - request is fast enough
|
||||
}).catch(() => null);
|
||||
signal: new AbortController().signal, // Won't abort - request is fast enough
|
||||
}).catch(() => null)
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -89,183 +95,93 @@ function createExplanationPromise(props: PermissionExplanationProps): Promise<Pe
|
||||
* Creates the fetch promise lazily (only when user hits Ctrl+E)
|
||||
* to avoid consuming tokens for explanations users never view.
|
||||
*/
|
||||
export function usePermissionExplainerUI(props) {
|
||||
const $ = _c(9);
|
||||
let t0;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t0 = isPermissionExplainerEnabled();
|
||||
$[0] = t0;
|
||||
} else {
|
||||
t0 = $[0];
|
||||
}
|
||||
const enabled = t0;
|
||||
const [visible, setVisible] = useState(false);
|
||||
const [promise, setPromise] = useState(null);
|
||||
let t1;
|
||||
if ($[1] !== promise || $[2] !== props || $[3] !== visible) {
|
||||
t1 = () => {
|
||||
export function usePermissionExplainerUI(
|
||||
props: PermissionExplanationProps,
|
||||
): ExplainerState {
|
||||
const enabled = isPermissionExplainerEnabled()
|
||||
const [visible, setVisible] = useState(false)
|
||||
const [promise, setPromise] =
|
||||
useState<Promise<PermissionExplanationType | null> | null>(null)
|
||||
|
||||
// Use keybinding for ctrl+e toggle (configurable via keybindings.json)
|
||||
useKeybinding(
|
||||
'confirm:toggleExplanation',
|
||||
() => {
|
||||
if (!visible) {
|
||||
logEvent("tengu_permission_explainer_shortcut_used", {});
|
||||
logEvent('tengu_permission_explainer_shortcut_used', {})
|
||||
// Only create the promise on first toggle (lazy loading)
|
||||
if (!promise) {
|
||||
setPromise(createExplanationPromise(props));
|
||||
setPromise(createExplanationPromise(props))
|
||||
}
|
||||
}
|
||||
setVisible(_temp);
|
||||
};
|
||||
$[1] = promise;
|
||||
$[2] = props;
|
||||
$[3] = visible;
|
||||
$[4] = t1;
|
||||
} else {
|
||||
t1 = $[4];
|
||||
}
|
||||
let t2;
|
||||
if ($[5] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t2 = {
|
||||
context: "Confirmation",
|
||||
isActive: enabled
|
||||
};
|
||||
$[5] = t2;
|
||||
} else {
|
||||
t2 = $[5];
|
||||
}
|
||||
useKeybinding("confirm:toggleExplanation", t1, t2);
|
||||
let t3;
|
||||
if ($[6] !== promise || $[7] !== visible) {
|
||||
t3 = {
|
||||
visible,
|
||||
enabled,
|
||||
promise
|
||||
};
|
||||
$[6] = promise;
|
||||
$[7] = visible;
|
||||
$[8] = t3;
|
||||
} else {
|
||||
t3 = $[8];
|
||||
}
|
||||
return t3;
|
||||
setVisible(v => !v)
|
||||
},
|
||||
{ context: 'Confirmation', isActive: enabled },
|
||||
)
|
||||
|
||||
return { visible, enabled, promise }
|
||||
}
|
||||
|
||||
/**
|
||||
* Inner component that uses React 19's use() to read the promise.
|
||||
* Suspends while loading, returns null on error.
|
||||
*/
|
||||
function _temp(v) {
|
||||
return !v;
|
||||
}
|
||||
function ExplanationResult(t0) {
|
||||
const $ = _c(21);
|
||||
const {
|
||||
promise
|
||||
} = t0;
|
||||
const explanation = use(promise) as PermissionExplanationType | null;
|
||||
function ExplanationResult({
|
||||
promise,
|
||||
}: {
|
||||
promise: Promise<PermissionExplanationType | null>
|
||||
}): React.ReactNode {
|
||||
const explanation = use(promise)
|
||||
|
||||
if (!explanation) {
|
||||
let t1;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = <Box marginTop={1}><Text dimColor={true}>Explanation unavailable</Text></Box>;
|
||||
$[0] = t1;
|
||||
} else {
|
||||
t1 = $[0];
|
||||
}
|
||||
return t1;
|
||||
return (
|
||||
<Box marginTop={1}>
|
||||
<Text dimColor>Explanation unavailable</Text>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
let t1;
|
||||
if ($[1] !== explanation.explanation) {
|
||||
t1 = <Text>{explanation.explanation}</Text>;
|
||||
$[1] = explanation.explanation;
|
||||
$[2] = t1;
|
||||
} else {
|
||||
t1 = $[2];
|
||||
}
|
||||
let t2;
|
||||
if ($[3] !== explanation.reasoning) {
|
||||
t2 = <Box marginTop={1}><Text>{explanation.reasoning}</Text></Box>;
|
||||
$[3] = explanation.reasoning;
|
||||
$[4] = t2;
|
||||
} else {
|
||||
t2 = $[4];
|
||||
}
|
||||
let t3;
|
||||
if ($[5] !== explanation.riskLevel) {
|
||||
t3 = getRiskColor(explanation.riskLevel);
|
||||
$[5] = explanation.riskLevel;
|
||||
$[6] = t3;
|
||||
} else {
|
||||
t3 = $[6];
|
||||
}
|
||||
let t4;
|
||||
if ($[7] !== explanation.riskLevel) {
|
||||
t4 = getRiskLabel(explanation.riskLevel);
|
||||
$[7] = explanation.riskLevel;
|
||||
$[8] = t4;
|
||||
} else {
|
||||
t4 = $[8];
|
||||
}
|
||||
let t5;
|
||||
if ($[9] !== t3 || $[10] !== t4) {
|
||||
t5 = <Text color={t3}>{t4}:</Text>;
|
||||
$[9] = t3;
|
||||
$[10] = t4;
|
||||
$[11] = t5;
|
||||
} else {
|
||||
t5 = $[11];
|
||||
}
|
||||
let t6;
|
||||
if ($[12] !== explanation.risk) {
|
||||
t6 = <Text> {explanation.risk}</Text>;
|
||||
$[12] = explanation.risk;
|
||||
$[13] = t6;
|
||||
} else {
|
||||
t6 = $[13];
|
||||
}
|
||||
let t7;
|
||||
if ($[14] !== t5 || $[15] !== t6) {
|
||||
t7 = <Box marginTop={1}><Text>{t5}{t6}</Text></Box>;
|
||||
$[14] = t5;
|
||||
$[15] = t6;
|
||||
$[16] = t7;
|
||||
} else {
|
||||
t7 = $[16];
|
||||
}
|
||||
let t8;
|
||||
if ($[17] !== t1 || $[18] !== t2 || $[19] !== t7) {
|
||||
t8 = <Box flexDirection="column" marginTop={1}>{t1}{t2}{t7}</Box>;
|
||||
$[17] = t1;
|
||||
$[18] = t2;
|
||||
$[19] = t7;
|
||||
$[20] = t8;
|
||||
} else {
|
||||
t8 = $[20];
|
||||
}
|
||||
return t8;
|
||||
|
||||
return (
|
||||
<Box flexDirection="column" marginTop={1}>
|
||||
<Text>{explanation.explanation}</Text>
|
||||
<Box marginTop={1}>
|
||||
<Text>{explanation.reasoning}</Text>
|
||||
</Box>
|
||||
<Box marginTop={1}>
|
||||
<Text>
|
||||
<Text color={getRiskColor(explanation.riskLevel)}>
|
||||
{getRiskLabel(explanation.riskLevel)}:
|
||||
</Text>
|
||||
<Text> {explanation.risk}</Text>
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Content component - shows loading (via Suspense) or explanation when visible
|
||||
*/
|
||||
export function PermissionExplainerContent(t0) {
|
||||
const $ = _c(3);
|
||||
const {
|
||||
visible,
|
||||
promise
|
||||
} = t0;
|
||||
export function PermissionExplainerContent({
|
||||
visible,
|
||||
promise,
|
||||
}: {
|
||||
visible: boolean
|
||||
promise: Promise<PermissionExplanationType | null> | null
|
||||
}): React.ReactNode {
|
||||
if (!visible || !promise) {
|
||||
return null;
|
||||
return null
|
||||
}
|
||||
let t1;
|
||||
if ($[0] === Symbol.for("react.memo_cache_sentinel")) {
|
||||
t1 = <Box marginTop={1}><ShimmerLoadingText /></Box>;
|
||||
$[0] = t1;
|
||||
} else {
|
||||
t1 = $[0];
|
||||
}
|
||||
let t2;
|
||||
if ($[1] !== promise) {
|
||||
t2 = <Suspense fallback={t1}><ExplanationResult promise={promise} /></Suspense>;
|
||||
$[1] = promise;
|
||||
$[2] = t2;
|
||||
} else {
|
||||
t2 = $[2];
|
||||
}
|
||||
return t2;
|
||||
|
||||
return (
|
||||
<Suspense
|
||||
fallback={
|
||||
<Box marginTop={1}>
|
||||
<ShimmerLoadingText />
|
||||
</Box>
|
||||
}
|
||||
>
|
||||
<ExplanationResult promise={promise} />
|
||||
</Suspense>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user