mirror of
https://github.com/claude-code-best/claude-code.git
synced 2026-06-22 16: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,58 +1,57 @@
|
||||
import { APIUserAbortError } from '@anthropic-ai/sdk';
|
||||
import React, { type ReactNode, useCallback, useRef, useState } from 'react';
|
||||
import { useMainLoopModel } from '../../../../hooks/useMainLoopModel.js';
|
||||
import { Box, Text } from '../../../../ink.js';
|
||||
import { useKeybinding } from '../../../../keybindings/useKeybinding.js';
|
||||
import { createAbortController } from '../../../../utils/abortController.js';
|
||||
import { editPromptInEditor } from '../../../../utils/promptEditor.js';
|
||||
import { ConfigurableShortcutHint } from '../../../ConfigurableShortcutHint.js';
|
||||
import { Byline } from '../../../design-system/Byline.js';
|
||||
import { Spinner } from '../../../Spinner.js';
|
||||
import TextInput from '../../../TextInput.js';
|
||||
import { useWizard } from '../../../wizard/index.js';
|
||||
import { WizardDialogLayout } from '../../../wizard/WizardDialogLayout.js';
|
||||
import { generateAgent } from '../../generateAgent.js';
|
||||
import type { AgentWizardData } from '../types.js';
|
||||
import { APIUserAbortError } from '@anthropic-ai/sdk'
|
||||
import React, { type ReactNode, useCallback, useRef, useState } from 'react'
|
||||
import { useMainLoopModel } from '../../../../hooks/useMainLoopModel.js'
|
||||
import { Box, Text } from '../../../../ink.js'
|
||||
import { useKeybinding } from '../../../../keybindings/useKeybinding.js'
|
||||
import { createAbortController } from '../../../../utils/abortController.js'
|
||||
import { editPromptInEditor } from '../../../../utils/promptEditor.js'
|
||||
import { ConfigurableShortcutHint } from '../../../ConfigurableShortcutHint.js'
|
||||
import { Byline } from '../../../design-system/Byline.js'
|
||||
import { Spinner } from '../../../Spinner.js'
|
||||
import TextInput from '../../../TextInput.js'
|
||||
import { useWizard } from '../../../wizard/index.js'
|
||||
import { WizardDialogLayout } from '../../../wizard/WizardDialogLayout.js'
|
||||
import { generateAgent } from '../../generateAgent.js'
|
||||
import type { AgentWizardData } from '../types.js'
|
||||
|
||||
export function GenerateStep(): ReactNode {
|
||||
const {
|
||||
updateWizardData,
|
||||
goBack,
|
||||
goToStep,
|
||||
wizardData
|
||||
} = useWizard<AgentWizardData>();
|
||||
const [prompt, setPrompt] = useState(wizardData.generationPrompt || '');
|
||||
const [isGenerating, setIsGenerating] = useState(false);
|
||||
const [error, setError] = useState<string | null>(null);
|
||||
const [cursorOffset, setCursorOffset] = useState(prompt.length);
|
||||
const model = useMainLoopModel();
|
||||
const abortControllerRef = useRef<AbortController | null>(null);
|
||||
const { updateWizardData, goBack, goToStep, wizardData } =
|
||||
useWizard<AgentWizardData>()
|
||||
const [prompt, setPrompt] = useState(wizardData.generationPrompt || '')
|
||||
const [isGenerating, setIsGenerating] = useState(false)
|
||||
const [error, setError] = useState<string | null>(null)
|
||||
const [cursorOffset, setCursorOffset] = useState(prompt.length)
|
||||
const model = useMainLoopModel()
|
||||
const abortControllerRef = useRef<AbortController | null>(null)
|
||||
|
||||
// Cancel generation when escape pressed during generation
|
||||
const handleCancelGeneration = useCallback(() => {
|
||||
if (abortControllerRef.current) {
|
||||
abortControllerRef.current.abort();
|
||||
abortControllerRef.current = null;
|
||||
setIsGenerating(false);
|
||||
setError('Generation cancelled');
|
||||
abortControllerRef.current.abort()
|
||||
abortControllerRef.current = null
|
||||
setIsGenerating(false)
|
||||
setError('Generation cancelled')
|
||||
}
|
||||
}, []);
|
||||
}, [])
|
||||
|
||||
// Use Settings context so 'n' key doesn't cancel (allows typing 'n' in prompt input)
|
||||
useKeybinding('confirm:no', handleCancelGeneration, {
|
||||
context: 'Settings',
|
||||
isActive: isGenerating
|
||||
});
|
||||
isActive: isGenerating,
|
||||
})
|
||||
|
||||
const handleExternalEditor = useCallback(async () => {
|
||||
const result = await editPromptInEditor(prompt);
|
||||
const result = await editPromptInEditor(prompt)
|
||||
if (result.content !== null) {
|
||||
setPrompt(result.content);
|
||||
setCursorOffset(result.content.length);
|
||||
setPrompt(result.content)
|
||||
setCursorOffset(result.content.length)
|
||||
}
|
||||
}, [prompt]);
|
||||
}, [prompt])
|
||||
|
||||
useKeybinding('chat:externalEditor', handleExternalEditor, {
|
||||
context: 'Chat',
|
||||
isActive: !isGenerating
|
||||
});
|
||||
isActive: !isGenerating,
|
||||
})
|
||||
|
||||
// Go back when escape pressed while not generating
|
||||
const handleGoBack = useCallback(() => {
|
||||
@@ -62,81 +61,141 @@ export function GenerateStep(): ReactNode {
|
||||
systemPrompt: '',
|
||||
whenToUse: '',
|
||||
generatedAgent: undefined,
|
||||
wasGenerated: false
|
||||
});
|
||||
setPrompt('');
|
||||
setError(null);
|
||||
goBack();
|
||||
}, [updateWizardData, goBack]);
|
||||
wasGenerated: false,
|
||||
})
|
||||
setPrompt('')
|
||||
setError(null)
|
||||
goBack()
|
||||
}, [updateWizardData, goBack])
|
||||
|
||||
// Use Settings context so 'n' key doesn't cancel (allows typing 'n' in prompt input)
|
||||
useKeybinding('confirm:no', handleGoBack, {
|
||||
context: 'Settings',
|
||||
isActive: !isGenerating
|
||||
});
|
||||
isActive: !isGenerating,
|
||||
})
|
||||
|
||||
const handleGenerate = async (): Promise<void> => {
|
||||
const trimmedPrompt = prompt.trim();
|
||||
const trimmedPrompt = prompt.trim()
|
||||
if (!trimmedPrompt) {
|
||||
setError('Please describe what the agent should do');
|
||||
return;
|
||||
setError('Please describe what the agent should do')
|
||||
return
|
||||
}
|
||||
setError(null);
|
||||
setIsGenerating(true);
|
||||
|
||||
setError(null)
|
||||
setIsGenerating(true)
|
||||
updateWizardData({
|
||||
generationPrompt: trimmedPrompt,
|
||||
isGenerating: true
|
||||
});
|
||||
isGenerating: true,
|
||||
})
|
||||
|
||||
// Create abort controller for this generation
|
||||
const controller = createAbortController();
|
||||
abortControllerRef.current = controller;
|
||||
const controller = createAbortController()
|
||||
abortControllerRef.current = controller
|
||||
|
||||
try {
|
||||
const generated = await generateAgent(trimmedPrompt, model, [], controller.signal);
|
||||
const generated = await generateAgent(
|
||||
trimmedPrompt,
|
||||
model,
|
||||
[],
|
||||
controller.signal,
|
||||
)
|
||||
|
||||
updateWizardData({
|
||||
agentType: generated.identifier,
|
||||
whenToUse: generated.whenToUse,
|
||||
systemPrompt: generated.systemPrompt,
|
||||
generatedAgent: generated,
|
||||
isGenerating: false,
|
||||
wasGenerated: true
|
||||
});
|
||||
wasGenerated: true,
|
||||
})
|
||||
|
||||
// Skip directly to ToolsStep (index 6) - matching original flow
|
||||
goToStep(6);
|
||||
goToStep(6)
|
||||
} catch (err) {
|
||||
// Don't show error if it was cancelled (already set in escape handler)
|
||||
if (err instanceof APIUserAbortError) {
|
||||
// User cancelled - no error to show
|
||||
} else if (err instanceof Error && !err.message.includes('No assistant message found')) {
|
||||
setError(err.message || 'Failed to generate agent');
|
||||
} else if (
|
||||
err instanceof Error &&
|
||||
!err.message.includes('No assistant message found')
|
||||
) {
|
||||
setError(err.message || 'Failed to generate agent')
|
||||
}
|
||||
updateWizardData({
|
||||
isGenerating: false
|
||||
});
|
||||
updateWizardData({ isGenerating: false })
|
||||
} finally {
|
||||
setIsGenerating(false);
|
||||
abortControllerRef.current = null;
|
||||
setIsGenerating(false)
|
||||
abortControllerRef.current = null
|
||||
}
|
||||
};
|
||||
const subtitle = 'Describe what this agent should do and when it should be used (be comprehensive for best results)';
|
||||
}
|
||||
|
||||
const subtitle =
|
||||
'Describe what this agent should do and when it should be used (be comprehensive for best results)'
|
||||
|
||||
if (isGenerating) {
|
||||
return <WizardDialogLayout subtitle={subtitle} footerText={<ConfigurableShortcutHint action="confirm:no" context="Settings" fallback="Esc" description="cancel" />}>
|
||||
return (
|
||||
<WizardDialogLayout
|
||||
subtitle={subtitle}
|
||||
footerText={
|
||||
<ConfigurableShortcutHint
|
||||
action="confirm:no"
|
||||
context="Settings"
|
||||
fallback="Esc"
|
||||
description="cancel"
|
||||
/>
|
||||
}
|
||||
>
|
||||
<Box flexDirection="row" alignItems="center">
|
||||
<Spinner />
|
||||
<Text color="suggestion"> Generating agent from description...</Text>
|
||||
</Box>
|
||||
</WizardDialogLayout>;
|
||||
</WizardDialogLayout>
|
||||
)
|
||||
}
|
||||
return <WizardDialogLayout subtitle={subtitle} footerText={<Byline>
|
||||
<ConfigurableShortcutHint action="confirm:yes" context="Confirmation" fallback="Enter" description="submit" />
|
||||
<ConfigurableShortcutHint action="chat:externalEditor" context="Chat" fallback="ctrl+g" description="open in editor" />
|
||||
<ConfigurableShortcutHint action="confirm:no" context="Settings" fallback="Esc" description="go back" />
|
||||
</Byline>}>
|
||||
|
||||
return (
|
||||
<WizardDialogLayout
|
||||
subtitle={subtitle}
|
||||
footerText={
|
||||
<Byline>
|
||||
<ConfigurableShortcutHint
|
||||
action="confirm:yes"
|
||||
context="Confirmation"
|
||||
fallback="Enter"
|
||||
description="submit"
|
||||
/>
|
||||
<ConfigurableShortcutHint
|
||||
action="chat:externalEditor"
|
||||
context="Chat"
|
||||
fallback="ctrl+g"
|
||||
description="open in editor"
|
||||
/>
|
||||
<ConfigurableShortcutHint
|
||||
action="confirm:no"
|
||||
context="Settings"
|
||||
fallback="Esc"
|
||||
description="go back"
|
||||
/>
|
||||
</Byline>
|
||||
}
|
||||
>
|
||||
<Box flexDirection="column">
|
||||
{error && <Box marginBottom={1}>
|
||||
{error && (
|
||||
<Box marginBottom={1}>
|
||||
<Text color="error">{error}</Text>
|
||||
</Box>}
|
||||
<TextInput value={prompt} onChange={setPrompt} onSubmit={handleGenerate} placeholder="e.g., Help me write unit tests for my code..." columns={80} cursorOffset={cursorOffset} onChangeCursorOffset={setCursorOffset} focus showCursor />
|
||||
</Box>
|
||||
)}
|
||||
<TextInput
|
||||
value={prompt}
|
||||
onChange={setPrompt}
|
||||
onSubmit={handleGenerate}
|
||||
placeholder="e.g., Help me write unit tests for my code..."
|
||||
columns={80}
|
||||
cursorOffset={cursorOffset}
|
||||
onChangeCursorOffset={setCursorOffset}
|
||||
focus
|
||||
showCursor
|
||||
/>
|
||||
</Box>
|
||||
</WizardDialogLayout>;
|
||||
</WizardDialogLayout>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user