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,148 +1,189 @@
|
||||
import * as React from 'react';
|
||||
import { useCallback, useEffect, useState } from 'react';
|
||||
import type { CommandResultDisplay } from '../../commands.js';
|
||||
import { TEARDROP_ASTERISK } from '../../constants/figures.js';
|
||||
import { useExitOnCtrlCDWithKeybindings } from '../../hooks/useExitOnCtrlCDWithKeybindings.js';
|
||||
import { setClipboard } from '../../ink/termio/osc.js';
|
||||
import * as React from 'react'
|
||||
import { useCallback, useEffect, useState } from 'react'
|
||||
import type { CommandResultDisplay } from '../../commands.js'
|
||||
import { TEARDROP_ASTERISK } from '../../constants/figures.js'
|
||||
import { useExitOnCtrlCDWithKeybindings } from '../../hooks/useExitOnCtrlCDWithKeybindings.js'
|
||||
import { setClipboard } from '../../ink/termio/osc.js'
|
||||
// eslint-disable-next-line custom-rules/prefer-use-keybindings -- enter to copy link
|
||||
import { Box, Link, Text, useInput } from '../../ink.js';
|
||||
import { useKeybinding } from '../../keybindings/useKeybinding.js';
|
||||
import { logEvent } from '../../services/analytics/index.js';
|
||||
import { fetchReferralRedemptions, formatCreditAmount, getCachedOrFetchPassesEligibility } from '../../services/api/referral.js';
|
||||
import type { ReferralRedemptionsResponse, ReferrerRewardInfo } from '../../services/oauth/types.js';
|
||||
import { count } from '../../utils/array.js';
|
||||
import { logError } from '../../utils/log.js';
|
||||
import { Pane } from '../design-system/Pane.js';
|
||||
import { Box, Link, Text, useInput } from '../../ink.js'
|
||||
import { useKeybinding } from '../../keybindings/useKeybinding.js'
|
||||
import { logEvent } from '../../services/analytics/index.js'
|
||||
import {
|
||||
fetchReferralRedemptions,
|
||||
formatCreditAmount,
|
||||
getCachedOrFetchPassesEligibility,
|
||||
} from '../../services/api/referral.js'
|
||||
import type {
|
||||
ReferralRedemptionsResponse,
|
||||
ReferrerRewardInfo,
|
||||
} from '../../services/oauth/types.js'
|
||||
import { count } from '../../utils/array.js'
|
||||
import { logError } from '../../utils/log.js'
|
||||
import { Pane } from '../design-system/Pane.js'
|
||||
|
||||
type PassStatus = {
|
||||
passNumber: number;
|
||||
isAvailable: boolean;
|
||||
};
|
||||
passNumber: number
|
||||
isAvailable: boolean
|
||||
}
|
||||
|
||||
type Props = {
|
||||
onDone: (result?: string, options?: {
|
||||
display?: CommandResultDisplay;
|
||||
}) => void;
|
||||
};
|
||||
export function Passes({
|
||||
onDone
|
||||
}: Props): React.ReactNode {
|
||||
const [loading, setLoading] = useState(true);
|
||||
const [passStatuses, setPassStatuses] = useState<PassStatus[]>([]);
|
||||
const [isAvailable, setIsAvailable] = useState(false);
|
||||
const [referralLink, setReferralLink] = useState<string | null>(null);
|
||||
const [referrerReward, setReferrerReward] = useState<ReferrerRewardInfo | null | undefined>(undefined);
|
||||
const exitState = useExitOnCtrlCDWithKeybindings(() => onDone('Guest passes dialog dismissed', {
|
||||
display: 'system'
|
||||
}));
|
||||
onDone: (
|
||||
result?: string,
|
||||
options?: { display?: CommandResultDisplay },
|
||||
) => void
|
||||
}
|
||||
|
||||
export function Passes({ onDone }: Props): React.ReactNode {
|
||||
const [loading, setLoading] = useState(true)
|
||||
const [passStatuses, setPassStatuses] = useState<PassStatus[]>([])
|
||||
const [isAvailable, setIsAvailable] = useState(false)
|
||||
const [referralLink, setReferralLink] = useState<string | null>(null)
|
||||
const [referrerReward, setReferrerReward] = useState<
|
||||
ReferrerRewardInfo | null | undefined
|
||||
>(undefined)
|
||||
|
||||
const exitState = useExitOnCtrlCDWithKeybindings(() =>
|
||||
onDone('Guest passes dialog dismissed', { display: 'system' }),
|
||||
)
|
||||
|
||||
const handleCancel = useCallback(() => {
|
||||
onDone('Guest passes dialog dismissed', {
|
||||
display: 'system'
|
||||
});
|
||||
}, [onDone]);
|
||||
useKeybinding('confirm:no', handleCancel, {
|
||||
context: 'Confirmation'
|
||||
});
|
||||
onDone('Guest passes dialog dismissed', { display: 'system' })
|
||||
}, [onDone])
|
||||
|
||||
useKeybinding('confirm:no', handleCancel, { context: 'Confirmation' })
|
||||
|
||||
useInput((_input, key) => {
|
||||
if (key.return && referralLink) {
|
||||
void setClipboard(referralLink).then(raw => {
|
||||
if (raw) process.stdout.write(raw);
|
||||
logEvent('tengu_guest_passes_link_copied', {});
|
||||
onDone(`Referral link copied to clipboard!`);
|
||||
});
|
||||
if (raw) process.stdout.write(raw)
|
||||
logEvent('tengu_guest_passes_link_copied', {})
|
||||
onDone(`Referral link copied to clipboard!`)
|
||||
})
|
||||
}
|
||||
});
|
||||
})
|
||||
|
||||
useEffect(() => {
|
||||
async function loadPassesData() {
|
||||
try {
|
||||
// Check eligibility first (uses cache if available)
|
||||
const eligibilityData = await getCachedOrFetchPassesEligibility();
|
||||
const eligibilityData = await getCachedOrFetchPassesEligibility()
|
||||
|
||||
if (!eligibilityData || !eligibilityData.eligible) {
|
||||
setIsAvailable(false);
|
||||
setLoading(false);
|
||||
return;
|
||||
setIsAvailable(false)
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
setIsAvailable(true);
|
||||
|
||||
setIsAvailable(true)
|
||||
|
||||
// Store the referral link if available
|
||||
if (eligibilityData.referral_code_details?.referral_link) {
|
||||
setReferralLink(eligibilityData.referral_code_details.referral_link);
|
||||
setReferralLink(eligibilityData.referral_code_details.referral_link)
|
||||
}
|
||||
|
||||
// Store referrer reward info for v1 campaign messaging
|
||||
setReferrerReward(eligibilityData.referrer_reward);
|
||||
setReferrerReward(eligibilityData.referrer_reward)
|
||||
|
||||
// Use the campaign returned from eligibility for redemptions
|
||||
const campaign = eligibilityData.referral_code_details?.campaign ?? 'claude_code_guest_pass';
|
||||
const campaign =
|
||||
eligibilityData.referral_code_details?.campaign ??
|
||||
'claude_code_guest_pass'
|
||||
|
||||
// Fetch redemptions data
|
||||
let redemptionsData: ReferralRedemptionsResponse;
|
||||
let redemptionsData: ReferralRedemptionsResponse
|
||||
try {
|
||||
redemptionsData = await fetchReferralRedemptions(campaign);
|
||||
} catch (err_0) {
|
||||
logError(err_0 as Error);
|
||||
setIsAvailable(false);
|
||||
setLoading(false);
|
||||
return;
|
||||
redemptionsData = await fetchReferralRedemptions(campaign)
|
||||
} catch (err) {
|
||||
logError(err as Error)
|
||||
setIsAvailable(false)
|
||||
setLoading(false)
|
||||
return
|
||||
}
|
||||
|
||||
// Build pass statuses array
|
||||
const redemptions = redemptionsData.redemptions || [];
|
||||
const maxRedemptions = redemptionsData.limit || 3;
|
||||
const statuses: PassStatus[] = [];
|
||||
const redemptions = redemptionsData.redemptions || []
|
||||
const maxRedemptions = redemptionsData.limit || 3
|
||||
const statuses: PassStatus[] = []
|
||||
|
||||
for (let i = 0; i < maxRedemptions; i++) {
|
||||
const redemption = redemptions[i];
|
||||
const redemption = redemptions[i]
|
||||
statuses.push({
|
||||
passNumber: i + 1,
|
||||
isAvailable: !redemption
|
||||
});
|
||||
isAvailable: !redemption,
|
||||
})
|
||||
}
|
||||
setPassStatuses(statuses);
|
||||
setLoading(false);
|
||||
|
||||
setPassStatuses(statuses)
|
||||
setLoading(false)
|
||||
} catch (err) {
|
||||
// For any error, just show passes as not available
|
||||
logError(err as Error);
|
||||
setIsAvailable(false);
|
||||
setLoading(false);
|
||||
logError(err as Error)
|
||||
setIsAvailable(false)
|
||||
setLoading(false)
|
||||
}
|
||||
}
|
||||
void loadPassesData();
|
||||
}, []);
|
||||
|
||||
void loadPassesData()
|
||||
}, [])
|
||||
|
||||
if (loading) {
|
||||
return <Pane>
|
||||
return (
|
||||
<Pane>
|
||||
<Box flexDirection="column" gap={1}>
|
||||
<Text dimColor>Loading guest pass information…</Text>
|
||||
<Text dimColor italic>
|
||||
{exitState.pending ? <>Press {exitState.keyName} again to exit</> : <>Esc to cancel</>}
|
||||
{exitState.pending ? (
|
||||
<>Press {exitState.keyName} again to exit</>
|
||||
) : (
|
||||
<>Esc to cancel</>
|
||||
)}
|
||||
</Text>
|
||||
</Box>
|
||||
</Pane>;
|
||||
</Pane>
|
||||
)
|
||||
}
|
||||
|
||||
if (!isAvailable) {
|
||||
return <Pane>
|
||||
return (
|
||||
<Pane>
|
||||
<Box flexDirection="column" gap={1}>
|
||||
<Text>Guest passes are not currently available.</Text>
|
||||
<Text dimColor italic>
|
||||
{exitState.pending ? <>Press {exitState.keyName} again to exit</> : <>Esc to cancel</>}
|
||||
{exitState.pending ? (
|
||||
<>Press {exitState.keyName} again to exit</>
|
||||
) : (
|
||||
<>Esc to cancel</>
|
||||
)}
|
||||
</Text>
|
||||
</Box>
|
||||
</Pane>;
|
||||
</Pane>
|
||||
)
|
||||
}
|
||||
const availableCount = count(passStatuses, p => p.isAvailable);
|
||||
|
||||
const availableCount = count(passStatuses, p => p.isAvailable)
|
||||
|
||||
// Sort passes: available first, then redeemed
|
||||
const sortedPasses = [...passStatuses].sort((a, b) => +b.isAvailable - +a.isAvailable);
|
||||
const sortedPasses = [...passStatuses].sort(
|
||||
(a, b) => +b.isAvailable - +a.isAvailable,
|
||||
)
|
||||
|
||||
// ASCII art for tickets
|
||||
const renderTicket = (pass: PassStatus) => {
|
||||
const isRedeemed = !pass.isAvailable;
|
||||
const isRedeemed = !pass.isAvailable
|
||||
|
||||
if (isRedeemed) {
|
||||
// Grayed out redeemed ticket with slashes
|
||||
return <Box key={pass.passNumber} flexDirection="column" marginRight={1}>
|
||||
return (
|
||||
<Box key={pass.passNumber} flexDirection="column" marginRight={1}>
|
||||
<Text dimColor>{'┌─────────╱'}</Text>
|
||||
<Text dimColor>{` ) CC ${TEARDROP_ASTERISK} ┊╱`}</Text>
|
||||
<Text dimColor>{'└───────╱'}</Text>
|
||||
</Box>;
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
return <Box key={pass.passNumber} flexDirection="column" marginRight={1}>
|
||||
|
||||
return (
|
||||
<Box key={pass.passNumber} flexDirection="column" marginRight={1}>
|
||||
<Text>{'┌──────────┐'}</Text>
|
||||
<Text>
|
||||
{' ) CC '}
|
||||
@@ -150,24 +191,37 @@ export function Passes({
|
||||
{' ┊ ( '}
|
||||
</Text>
|
||||
<Text>{'└──────────┘'}</Text>
|
||||
</Box>;
|
||||
};
|
||||
return <Pane>
|
||||
</Box>
|
||||
)
|
||||
}
|
||||
|
||||
return (
|
||||
<Pane>
|
||||
<Box flexDirection="column" gap={1}>
|
||||
<Text color="permission">Guest passes · {availableCount} left</Text>
|
||||
|
||||
<Box flexDirection="row" marginLeft={2}>
|
||||
{sortedPasses.slice(0, 3).map(pass_0 => renderTicket(pass_0))}
|
||||
{sortedPasses.slice(0, 3).map(pass => renderTicket(pass))}
|
||||
</Box>
|
||||
|
||||
{referralLink && <Box marginLeft={2}>
|
||||
{referralLink && (
|
||||
<Box marginLeft={2}>
|
||||
<Text>{referralLink}</Text>
|
||||
</Box>}
|
||||
</Box>
|
||||
)}
|
||||
|
||||
<Box flexDirection="column" marginLeft={2}>
|
||||
<Text dimColor>
|
||||
{referrerReward ? `Share a free week of Claude Code with friends. If they love it and subscribe, you'll get ${formatCreditAmount(referrerReward)} of extra usage to keep building. ` : 'Share a free week of Claude Code with friends. '}
|
||||
<Link url={referrerReward ? 'https://support.claude.com/en/articles/13456702-claude-code-guest-passes' : 'https://support.claude.com/en/articles/12875061-claude-code-guest-passes'}>
|
||||
{referrerReward
|
||||
? `Share a free week of Claude Code with friends. If they love it and subscribe, you'll get ${formatCreditAmount(referrerReward)} of extra usage to keep building. `
|
||||
: 'Share a free week of Claude Code with friends. '}
|
||||
<Link
|
||||
url={
|
||||
referrerReward
|
||||
? 'https://support.claude.com/en/articles/13456702-claude-code-guest-passes'
|
||||
: 'https://support.claude.com/en/articles/12875061-claude-code-guest-passes'
|
||||
}
|
||||
>
|
||||
Terms apply.
|
||||
</Link>
|
||||
</Text>
|
||||
@@ -175,9 +229,14 @@ export function Passes({
|
||||
|
||||
<Box>
|
||||
<Text dimColor italic>
|
||||
{exitState.pending ? <>Press {exitState.keyName} again to exit</> : <>Enter to copy link · Esc to cancel</>}
|
||||
{exitState.pending ? (
|
||||
<>Press {exitState.keyName} again to exit</>
|
||||
) : (
|
||||
<>Enter to copy link · Esc to cancel</>
|
||||
)}
|
||||
</Text>
|
||||
</Box>
|
||||
</Box>
|
||||
</Pane>;
|
||||
</Pane>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user