mirror of
https://github.com/andrepimenta/claude-code-chat.git
synced 2025-12-13 13:49:47 +00:00
Fix new chat
This commit is contained in:
@@ -56,7 +56,6 @@ interface ConversationData {
|
||||
};
|
||||
messages: Array<{ timestamp: string, messageType: string, data: any }>;
|
||||
filename: string;
|
||||
isProcessing?: boolean;
|
||||
}
|
||||
|
||||
class ClaudeChatWebviewProvider implements vscode.WebviewViewProvider {
|
||||
@@ -573,6 +572,10 @@ class ClaudeChatProvider {
|
||||
console.log('Claude process closed with code:', code);
|
||||
console.log('Claude stderr output:', errorOutput);
|
||||
|
||||
if (!this._currentClaudeProcess) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear process reference
|
||||
this._currentClaudeProcess = undefined;
|
||||
|
||||
@@ -584,6 +587,12 @@ class ClaudeChatProvider {
|
||||
// Reset processing state
|
||||
this._isProcessing = false;
|
||||
|
||||
// Clear processing state
|
||||
this._postMessage({
|
||||
type: 'setProcessing',
|
||||
data: { isProcessing: false }
|
||||
});
|
||||
|
||||
if (code !== 0 && errorOutput.trim()) {
|
||||
// Error with output
|
||||
this._sendAndSaveMessage({
|
||||
@@ -596,6 +605,10 @@ class ClaudeChatProvider {
|
||||
claudeProcess.on('error', (error) => {
|
||||
console.log('Claude process error:', error.message);
|
||||
|
||||
if (!this._currentClaudeProcess) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Clear process reference
|
||||
this._currentClaudeProcess = undefined;
|
||||
|
||||
@@ -603,6 +616,14 @@ class ClaudeChatProvider {
|
||||
type: 'clearLoading'
|
||||
});
|
||||
|
||||
this._isProcessing = false;
|
||||
|
||||
// Clear processing state
|
||||
this._postMessage({
|
||||
type: 'setProcessing',
|
||||
data: { isProcessing: false }
|
||||
});
|
||||
|
||||
// Check if claude command is not installed
|
||||
if (error.message.includes('ENOENT') || error.message.includes('command not found')) {
|
||||
this._sendAndSaveMessage({
|
||||
@@ -624,6 +645,18 @@ class ClaudeChatProvider {
|
||||
if (jsonData.subtype === 'init') {
|
||||
// System initialization message - session ID will be captured from final result
|
||||
console.log('System initialized');
|
||||
this._currentSessionId = jsonData.session_id;
|
||||
//this._sendAndSaveMessage({ type: 'init', data: { sessionId: jsonData.session_id; } })
|
||||
|
||||
// Show session info in UI
|
||||
this._sendAndSaveMessage({
|
||||
type: 'sessionInfo',
|
||||
data: {
|
||||
sessionId: jsonData.session_id,
|
||||
tools: jsonData.tools || [],
|
||||
mcpServers: jsonData.mcp_servers || []
|
||||
}
|
||||
});
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -819,6 +852,22 @@ class ClaudeChatProvider {
|
||||
|
||||
|
||||
private _newSession() {
|
||||
|
||||
this._isProcessing = false
|
||||
|
||||
// Update UI state
|
||||
this._postMessage({
|
||||
type: 'setProcessing',
|
||||
data: { isProcessing: false }
|
||||
});
|
||||
|
||||
// Try graceful termination first
|
||||
if (this._currentClaudeProcess) {
|
||||
const processToKill = this._currentClaudeProcess;
|
||||
this._currentClaudeProcess = undefined;
|
||||
processToKill.kill('SIGTERM');
|
||||
}
|
||||
|
||||
// Clear current session
|
||||
this._currentSessionId = undefined;
|
||||
|
||||
@@ -1742,7 +1791,7 @@ class ClaudeChatProvider {
|
||||
return path.join(configPath);
|
||||
}
|
||||
|
||||
private _sendAndSaveMessage(message: { type: string, data: any }, options?: { isProcessing?: boolean }): void {
|
||||
private _sendAndSaveMessage(message: { type: string, data: any }): void {
|
||||
|
||||
// Initialize conversation if this is the first message
|
||||
if (this._currentConversation.length === 0) {
|
||||
@@ -1767,8 +1816,6 @@ class ClaudeChatProvider {
|
||||
if (!this._conversationsPath || this._currentConversation.length === 0) { return; }
|
||||
if (!this._currentSessionId) { return; }
|
||||
|
||||
console.log("IS PROCESSING", this._isProcessing)
|
||||
|
||||
try {
|
||||
// Create filename from first user message and timestamp
|
||||
const firstUserMessage = this._currentConversation.find(m => m.messageType === 'userInput');
|
||||
@@ -1800,10 +1847,6 @@ class ClaudeChatProvider {
|
||||
filename
|
||||
};
|
||||
|
||||
if (this._isProcessing !== undefined){
|
||||
conversationData.isProcessing = this._isProcessing || false
|
||||
}
|
||||
|
||||
const filePath = path.join(this._conversationsPath, filename);
|
||||
const content = new TextEncoder().encode(JSON.stringify(conversationData, null, 2));
|
||||
await vscode.workspace.fs.writeFile(vscode.Uri.file(filePath), content);
|
||||
@@ -2006,7 +2049,6 @@ class ClaudeChatProvider {
|
||||
return;
|
||||
}
|
||||
|
||||
console.log("conversationData-----", conversationData);
|
||||
// Load conversation into current state
|
||||
this._currentConversation = conversationData.messages || [];
|
||||
this._conversationStartTime = conversationData.startTime;
|
||||
@@ -2051,11 +2093,10 @@ class ClaudeChatProvider {
|
||||
});
|
||||
|
||||
// Restore processing state if the conversation was saved while processing
|
||||
if (conversationData.isProcessing) {
|
||||
this._isProcessing = conversationData.isProcessing;
|
||||
if (this._isProcessing) {
|
||||
this._postMessage({
|
||||
type: 'setProcessing',
|
||||
data: {isProcessing: conversationData.isProcessing, requestStartTime}
|
||||
data: { isProcessing: this._isProcessing, requestStartTime }
|
||||
});
|
||||
}
|
||||
// Send ready message after conversation is loaded
|
||||
|
||||
Reference in New Issue
Block a user