mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Fix state management when starting new task with menu button
This commit is contained in:
@@ -168,10 +168,6 @@ export class ClaudeDev {
|
|||||||
this.client = new Anthropic({ apiKey })
|
this.client = new Anthropic({ apiKey })
|
||||||
this.maxRequestsPerTask = maxRequestsPerTask ?? DEFAULT_MAX_REQUESTS_PER_TASK
|
this.maxRequestsPerTask = maxRequestsPerTask ?? DEFAULT_MAX_REQUESTS_PER_TASK
|
||||||
|
|
||||||
// conversationHistory (for API) and claudeMessages (for webview) need to be in sync
|
|
||||||
// if the extension process were killed, then on restart the claudeMessages might not be empty, so we need to set it to [] when we create a new ClaudeDev client (otherwise webview would show stale messages from previous session)
|
|
||||||
this.providerRef.deref()?.setClaudeMessages([])
|
|
||||||
|
|
||||||
this.startTask(task)
|
this.startTask(task)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -206,6 +202,11 @@ export class ClaudeDev {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private async startTask(task: string): Promise<void> {
|
private async startTask(task: string): Promise<void> {
|
||||||
|
// conversationHistory (for API) and claudeMessages (for webview) need to be in sync
|
||||||
|
// if the extension process were killed, then on restart the claudeMessages might not be empty, so we need to set it to [] when we create a new ClaudeDev client (otherwise webview would show stale messages from previous session)
|
||||||
|
await this.providerRef.deref()?.setClaudeMessages([])
|
||||||
|
await this.providerRef.deref()?.postStateToWebview()
|
||||||
|
|
||||||
// Get all relevant context for the task
|
// Get all relevant context for the task
|
||||||
const filesInCurrentDir = await this.listFiles()
|
const filesInCurrentDir = await this.listFiles()
|
||||||
|
|
||||||
|
|||||||
@@ -34,10 +34,12 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
context.subscriptions.push(vscode.window.registerWebviewViewProvider(SidebarProvider.viewType, provider))
|
context.subscriptions.push(vscode.window.registerWebviewViewProvider(SidebarProvider.viewType, provider))
|
||||||
|
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
vscode.commands.registerCommand("claude-dev.plusButtonTapped", () => {
|
vscode.commands.registerCommand("claude-dev.plusButtonTapped", async () => {
|
||||||
const message = "claude-dev.plusButtonTapped!"
|
const message = "claude-dev.plusButtonTapped!"
|
||||||
vscode.window.showInformationMessage(message)
|
//vscode.window.showInformationMessage(message)
|
||||||
provider.postMessageToWebview({ type: "action", action: "plusButtonTapped"})
|
await provider.resetTask()
|
||||||
|
await provider.postStateToWebview()
|
||||||
|
await provider.postMessageToWebview({ type: "action", action: "plusButtonTapped"})
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
@@ -13,7 +13,7 @@ https://github.com/KumarVariable/vscode-extension-sidebar-html/blob/master/src/c
|
|||||||
|
|
||||||
type ExtensionSecretKey = "apiKey"
|
type ExtensionSecretKey = "apiKey"
|
||||||
type ExtensionGlobalStateKey = "didOpenOnce" | "maxRequestsPerTask"
|
type ExtensionGlobalStateKey = "didOpenOnce" | "maxRequestsPerTask"
|
||||||
type ExtensionWorkspaceStateKey = "claudeMessages" | "apiConversationHistory"
|
type ExtensionWorkspaceStateKey = "claudeMessages"
|
||||||
|
|
||||||
export class SidebarProvider implements vscode.WebviewViewProvider {
|
export class SidebarProvider implements vscode.WebviewViewProvider {
|
||||||
public static readonly viewType = "claude-dev.SidebarProvider"
|
public static readonly viewType = "claude-dev.SidebarProvider"
|
||||||
@@ -40,6 +40,9 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
|
|||||||
// Sets up an event listener to listen for messages passed from the webview view context
|
// Sets up an event listener to listen for messages passed from the webview view context
|
||||||
// and executes code based on the message that is recieved
|
// and executes code based on the message that is recieved
|
||||||
this.setWebviewMessageListener(webviewView.webview)
|
this.setWebviewMessageListener(webviewView.webview)
|
||||||
|
|
||||||
|
// if the extension is starting a new session, clear previous task state
|
||||||
|
this.resetTask()
|
||||||
}
|
}
|
||||||
|
|
||||||
async tryToInitClaudeDevWithTask(task: string) {
|
async tryToInitClaudeDevWithTask(task: string) {
|
||||||
@@ -199,6 +202,11 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
|
|||||||
state: { didOpenOnce: !!didOpenOnce, apiKey, maxRequestsPerTask, claudeMessages },
|
state: { didOpenOnce: !!didOpenOnce, apiKey, maxRequestsPerTask, claudeMessages },
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async resetTask() {
|
||||||
|
this.claudeDev = undefined
|
||||||
|
await this.setClaudeMessages([])
|
||||||
|
}
|
||||||
|
|
||||||
// client messages
|
// client messages
|
||||||
|
|
||||||
@@ -220,21 +228,21 @@ export class SidebarProvider implements vscode.WebviewViewProvider {
|
|||||||
|
|
||||||
// api conversation history
|
// api conversation history
|
||||||
|
|
||||||
async getApiConversationHistory(): Promise<ClaudeMessage[]> {
|
// async getApiConversationHistory(): Promise<ClaudeMessage[]> {
|
||||||
const messages = (await this.getWorkspaceState("apiConversationHistory")) as ClaudeMessage[]
|
// const messages = (await this.getWorkspaceState("apiConversationHistory")) as ClaudeMessage[]
|
||||||
return messages || []
|
// return messages || []
|
||||||
}
|
// }
|
||||||
|
|
||||||
async setApiConversationHistory(messages: ClaudeMessage[] | undefined) {
|
// async setApiConversationHistory(messages: ClaudeMessage[] | undefined) {
|
||||||
await this.updateWorkspaceState("apiConversationHistory", messages)
|
// await this.updateWorkspaceState("apiConversationHistory", messages)
|
||||||
}
|
// }
|
||||||
|
|
||||||
async addMessageToApiConversationHistory(message: ClaudeMessage): Promise<ClaudeMessage[]> {
|
// async addMessageToApiConversationHistory(message: ClaudeMessage): Promise<ClaudeMessage[]> {
|
||||||
const messages = await this.getClaudeMessages()
|
// const messages = await this.getClaudeMessages()
|
||||||
messages.push(message)
|
// messages.push(message)
|
||||||
await this.setClaudeMessages(messages)
|
// await this.setClaudeMessages(messages)
|
||||||
return messages
|
// return messages
|
||||||
}
|
// }
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Storage
|
Storage
|
||||||
|
|||||||
Reference in New Issue
Block a user