claude-code-best/src/components/TeleportRepoMismatchDialog.tsx
y574444354 d59d1f590a chore: 合并社区 upstream/main 代码至 v2.4.2
合并 claude-code-best/claude-code 社区最新代码,包含:
- 配置文件更新:precheck/lint-staged/overrides 等
- 新 feature flags:EXPERIMENTAL_SEARCH_EXTRA_TOOLS、AUTOFIX_PR
- 工具系统架构更新:Tool Search、ACP 协议支持
- 文档更新:CLAUDE.md 同步架构变更
- 依赖更新:SDK 版本升级、lint-staged 加入

冲突处理策略:以 costrict 版本为主,选择性合并上游功能改进
2026-05-12 11:55:04 +08:00

95 lines
2.7 KiB
TypeScript

import React, { useCallback, useState } from 'react';
import { Box, Text } from '@anthropic/ink';
import { getDisplayPath } from '../utils/file.js';
import { removePathFromRepo, validateRepoAtPath } from '../utils/githubRepoPathMapping.js';
import { Select } from './CustomSelect/index.js';
import { Dialog } from '@anthropic/ink';
import { Spinner } from './Spinner.js';
type Props = {
targetRepo: string;
initialPaths: string[];
onSelectPath: (path: string) => void;
onCancel: () => void;
};
export function TeleportRepoMismatchDialog({
targetRepo,
initialPaths,
onSelectPath,
onCancel,
}: Props): React.ReactNode {
const [availablePaths, setAvailablePaths] = useState<string[]>(initialPaths);
const [errorMessage, setErrorMessage] = useState<string | null>(null);
const [validating, setValidating] = useState(false);
const handleChange = useCallback(
async (value: string): Promise<void> => {
if (value === 'cancel') {
onCancel();
return;
}
setValidating(true);
setErrorMessage(null);
const isValid = await validateRepoAtPath(value, targetRepo);
if (isValid) {
onSelectPath(value);
return;
}
// Path is invalid - remove it from config and update state
removePathFromRepo(targetRepo, value);
const updatedPaths = availablePaths.filter(p => p !== value);
setAvailablePaths(updatedPaths);
setValidating(false);
setErrorMessage(`${getDisplayPath(value)} no longer contains the correct repository. Select another path.`);
},
[targetRepo, availablePaths, onSelectPath, onCancel],
);
const options = [
...availablePaths.map(path => ({
label: (
<Text>
Use <Text bold>{getDisplayPath(path)}</Text>
</Text>
),
value: path,
})),
{ label: 'Cancel', value: 'cancel' },
];
return (
<Dialog title="Teleport to Repo" onCancel={onCancel} color="background">
{availablePaths.length > 0 ? (
<>
<Box flexDirection="column" gap={1}>
{errorMessage && <Text color="error">{errorMessage}</Text>}
<Text>
Open CoStrict in <Text bold>{targetRepo}</Text>:
</Text>
</Box>
{validating ? (
<Box>
<Spinner />
<Text> Validating repository</Text>
</Box>
) : (
<Select options={options} onChange={value => void handleChange(value)} />
)}
</>
) : (
<Box flexDirection="column" gap={1}>
{errorMessage && <Text color="error">{errorMessage}</Text>}
<Text dimColor>Run claude --teleport from a checkout of {targetRepo}</Text>
</Box>
)}
</Dialog>
);
}