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,90 +1,121 @@
|
||||
import { join } from 'path';
|
||||
import React from 'react';
|
||||
import { ExportDialog } from '../../components/ExportDialog.js';
|
||||
import type { ToolUseContext } from '../../Tool.js';
|
||||
import type { LocalJSXCommandOnDone } from '../../types/command.js';
|
||||
import type { Message } from '../../types/message.js';
|
||||
import { getCwd } from '../../utils/cwd.js';
|
||||
import { renderMessagesToPlainText } from '../../utils/exportRenderer.js';
|
||||
import { writeFileSync_DEPRECATED } from '../../utils/slowOperations.js';
|
||||
import { join } from 'path'
|
||||
import React from 'react'
|
||||
import { ExportDialog } from '../../components/ExportDialog.js'
|
||||
import type { ToolUseContext } from '../../Tool.js'
|
||||
import type { LocalJSXCommandOnDone } from '../../types/command.js'
|
||||
import type { Message } from '../../types/message.js'
|
||||
import { getCwd } from '../../utils/cwd.js'
|
||||
import { renderMessagesToPlainText } from '../../utils/exportRenderer.js'
|
||||
import { writeFileSync_DEPRECATED } from '../../utils/slowOperations.js'
|
||||
|
||||
function formatTimestamp(date: Date): string {
|
||||
const year = date.getFullYear();
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0');
|
||||
const day = String(date.getDate()).padStart(2, '0');
|
||||
const hours = String(date.getHours()).padStart(2, '0');
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0');
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0');
|
||||
return `${year}-${month}-${day}-${hours}${minutes}${seconds}`;
|
||||
const year = date.getFullYear()
|
||||
const month = String(date.getMonth() + 1).padStart(2, '0')
|
||||
const day = String(date.getDate()).padStart(2, '0')
|
||||
const hours = String(date.getHours()).padStart(2, '0')
|
||||
const minutes = String(date.getMinutes()).padStart(2, '0')
|
||||
const seconds = String(date.getSeconds()).padStart(2, '0')
|
||||
return `${year}-${month}-${day}-${hours}${minutes}${seconds}`
|
||||
}
|
||||
|
||||
export function extractFirstPrompt(messages: Message[]): string {
|
||||
const firstUserMessage = messages.find(msg => msg.type === 'user');
|
||||
const firstUserMessage = messages.find(msg => msg.type === 'user')
|
||||
|
||||
if (!firstUserMessage || firstUserMessage.type !== 'user') {
|
||||
return '';
|
||||
return ''
|
||||
}
|
||||
const content = firstUserMessage.message?.content;
|
||||
let result = '';
|
||||
|
||||
const content = firstUserMessage.message?.content
|
||||
let result = ''
|
||||
|
||||
if (typeof content === 'string') {
|
||||
result = content.trim();
|
||||
result = content.trim()
|
||||
} else if (Array.isArray(content)) {
|
||||
const textContent = content.find(item => item.type === 'text');
|
||||
const textContent = content.find(item => item.type === 'text')
|
||||
if (textContent && 'text' in textContent) {
|
||||
result = textContent.text.trim();
|
||||
result = textContent.text.trim()
|
||||
}
|
||||
}
|
||||
|
||||
// Take first line only and limit length
|
||||
result = result.split('\n')[0] || '';
|
||||
result = result.split('\n')[0] || ''
|
||||
if (result.length > 50) {
|
||||
result = result.substring(0, 49) + '…';
|
||||
result = result.substring(0, 49) + '…'
|
||||
}
|
||||
return result;
|
||||
|
||||
return result
|
||||
}
|
||||
|
||||
export function sanitizeFilename(text: string): string {
|
||||
// Replace special characters with hyphens
|
||||
return text.toLowerCase().replace(/[^a-z0-9\s-]/g, '') // Remove special chars
|
||||
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
||||
.replace(/-+/g, '-') // Replace multiple hyphens with single
|
||||
.replace(/^-|-$/g, ''); // Remove leading/trailing hyphens
|
||||
return text
|
||||
.toLowerCase()
|
||||
.replace(/[^a-z0-9\s-]/g, '') // Remove special chars
|
||||
.replace(/\s+/g, '-') // Replace spaces with hyphens
|
||||
.replace(/-+/g, '-') // Replace multiple hyphens with single
|
||||
.replace(/^-|-$/g, '') // Remove leading/trailing hyphens
|
||||
}
|
||||
async function exportWithReactRenderer(context: ToolUseContext): Promise<string> {
|
||||
const tools = context.options.tools || [];
|
||||
return renderMessagesToPlainText(context.messages, tools);
|
||||
|
||||
async function exportWithReactRenderer(
|
||||
context: ToolUseContext,
|
||||
): Promise<string> {
|
||||
const tools = context.options.tools || []
|
||||
return renderMessagesToPlainText(context.messages, tools)
|
||||
}
|
||||
export async function call(onDone: LocalJSXCommandOnDone, context: ToolUseContext, args: string): Promise<React.ReactNode> {
|
||||
|
||||
export async function call(
|
||||
onDone: LocalJSXCommandOnDone,
|
||||
context: ToolUseContext,
|
||||
args: string,
|
||||
): Promise<React.ReactNode> {
|
||||
// Render the conversation content
|
||||
const content = await exportWithReactRenderer(context);
|
||||
const content = await exportWithReactRenderer(context)
|
||||
|
||||
// If args are provided, write directly to file and skip dialog
|
||||
const filename = args.trim();
|
||||
const filename = args.trim()
|
||||
if (filename) {
|
||||
const finalFilename = filename.endsWith('.txt') ? filename : filename.replace(/\.[^.]+$/, '') + '.txt';
|
||||
const filepath = join(getCwd(), finalFilename);
|
||||
const finalFilename = filename.endsWith('.txt')
|
||||
? filename
|
||||
: filename.replace(/\.[^.]+$/, '') + '.txt'
|
||||
const filepath = join(getCwd(), finalFilename)
|
||||
|
||||
try {
|
||||
writeFileSync_DEPRECATED(filepath, content, {
|
||||
encoding: 'utf-8',
|
||||
flush: true
|
||||
});
|
||||
onDone(`Conversation exported to: ${filepath}`);
|
||||
return null;
|
||||
flush: true,
|
||||
})
|
||||
onDone(`Conversation exported to: ${filepath}`)
|
||||
return null
|
||||
} catch (error) {
|
||||
onDone(`Failed to export conversation: ${error instanceof Error ? error.message : 'Unknown error'}`);
|
||||
return null;
|
||||
onDone(
|
||||
`Failed to export conversation: ${error instanceof Error ? error.message : 'Unknown error'}`,
|
||||
)
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
// Generate default filename from first prompt or timestamp
|
||||
const firstPrompt = extractFirstPrompt(context.messages);
|
||||
const timestamp = formatTimestamp(new Date());
|
||||
let defaultFilename: string;
|
||||
const firstPrompt = extractFirstPrompt(context.messages)
|
||||
const timestamp = formatTimestamp(new Date())
|
||||
|
||||
let defaultFilename: string
|
||||
if (firstPrompt) {
|
||||
const sanitized = sanitizeFilename(firstPrompt);
|
||||
defaultFilename = sanitized ? `${timestamp}-${sanitized}.txt` : `conversation-${timestamp}.txt`;
|
||||
const sanitized = sanitizeFilename(firstPrompt)
|
||||
defaultFilename = sanitized
|
||||
? `${timestamp}-${sanitized}.txt`
|
||||
: `conversation-${timestamp}.txt`
|
||||
} else {
|
||||
defaultFilename = `conversation-${timestamp}.txt`;
|
||||
defaultFilename = `conversation-${timestamp}.txt`
|
||||
}
|
||||
|
||||
// Return the dialog component when no args provided
|
||||
return <ExportDialog content={content} defaultFilename={defaultFilename} onDone={result => {
|
||||
onDone(result.message);
|
||||
}} />;
|
||||
return (
|
||||
<ExportDialog
|
||||
content={content}
|
||||
defaultFilename={defaultFilename}
|
||||
onDone={result => {
|
||||
onDone(result.message)
|
||||
}}
|
||||
/>
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user