Refactor ClaudeDev

This commit is contained in:
Saoud Rizwan
2024-10-05 23:33:45 -04:00
parent 23d664be8e
commit 83ce17db11
4 changed files with 13 additions and 13 deletions

View File

@@ -206,9 +206,9 @@ export class Cline {
text?: string,
partial?: boolean
): Promise<{ response: ClaudeAskResponse; text?: string; images?: string[] }> {
// If this ClaudeDev instance was aborted by the provider, then the only thing keeping us alive is a promise still running in the background, in which case we don't want to send its result to the webview as it is attached to a new instance of ClaudeDev now. So we can safely ignore the result of any active promises, and this class will be deallocated. (Although we set claudeDev = undefined in provider, that simply removes the reference to this instance, but the instance is still alive until this promise resolves or rejects.)
// If this Cline instance was aborted by the provider, then the only thing keeping us alive is a promise still running in the background, in which case we don't want to send its result to the webview as it is attached to a new instance of Cline now. So we can safely ignore the result of any active promises, and this class will be deallocated. (Although we set Cline = undefined in provider, that simply removes the reference to this instance, but the instance is still alive until this promise resolves or rejects.)
if (this.abort) {
throw new Error("ClaudeDev instance aborted")
throw new Error("Cline instance aborted")
}
let askTs: number
if (partial !== undefined) {
@@ -304,7 +304,7 @@ export class Cline {
async say(type: ClaudeSay, text?: string, images?: string[], partial?: boolean): Promise<undefined> {
if (this.abort) {
throw new Error("ClaudeDev instance aborted")
throw new Error("Cline instance aborted")
}
if (partial !== undefined) {
@@ -374,7 +374,7 @@ export class Cline {
private async startTask(task?: string, images?: 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)
// 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 Cline client (otherwise webview would show stale messages from previous session)
this.claudeMessages = []
this.apiConversationHistory = []
await this.providerRef.deref()?.postStateToWebview()
@@ -743,7 +743,7 @@ export class Cline {
async presentAssistantMessage() {
if (this.abort) {
throw new Error("ClaudeDev instance aborted")
throw new Error("Cline instance aborted")
}
if (this.presentAssistantMessageLocked) {
@@ -1554,7 +1554,7 @@ export class Cline {
includeFileDetails: boolean = false
): Promise<boolean> {
if (this.abort) {
throw new Error("ClaudeDev instance aborted")
throw new Error("Cline instance aborted")
}
if (this.consecutiveMistakeCount >= 3) {
@@ -1738,7 +1738,7 @@ export class Cline {
// need to call here in case the stream was aborted
if (this.abort) {
throw new Error("ClaudeDev instance aborted")
throw new Error("Cline instance aborted")
}
this.didCompleteReadingStream = true

View File

@@ -56,8 +56,8 @@ export function activate(context: vscode.ExtensionContext) {
})
)
const openClaudeDevInNewTab = async () => {
outputChannel.appendLine("Opening Claude Dev in new tab")
const openClineInNewTab = async () => {
outputChannel.appendLine("Opening Cline in new tab")
// (this example uses webviewProvider activation event which is necessary to deserialize cached webview, but since we use retainContextWhenHidden, we don't need to use that event)
// https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts
const tabProvider = new ClineProvider(context, outputChannel)
@@ -89,8 +89,8 @@ export function activate(context: vscode.ExtensionContext) {
await vscode.commands.executeCommand("workbench.action.lockEditorGroup")
}
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.popoutButtonTapped", openClaudeDevInNewTab))
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.openInNewTab", openClaudeDevInNewTab))
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.popoutButtonTapped", openClineInNewTab))
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.openInNewTab", openClineInNewTab))
context.subscriptions.push(
vscode.commands.registerCommand("claude-dev.settingsButtonTapped", () => {

View File

@@ -9,7 +9,7 @@ interface AnnouncementProps {
hideAnnouncement: () => void
}
/*
You must update the latestAnnouncementId in ClaudeDevProvider for new announcements to show to users. This new id will be compared with whats in state for the 'last announcement shown', and if it's different then the announcement will render. As soon as an announcement is shown, the id will be updated in state. This ensures that announcements are not shown more than once, even if the user doesn't close it themselves.
You must update the latestAnnouncementId in ClineProvider for new announcements to show to users. This new id will be compared with whats in state for the 'last announcement shown', and if it's different then the announcement will render. As soon as an announcement is shown, the id will be updated in state. This ensures that announcements are not shown more than once, even if the user doesn't close it themselves.
*/
const Announcement = ({ version, hideAnnouncement }: AnnouncementProps) => {
return (

View File

@@ -31,7 +31,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
const { version, claudeMessages: messages, taskHistory, apiConfiguration } = useExtensionState()
//const task = messages.length > 0 ? (messages[0].say === "task" ? messages[0] : undefined) : undefined) : undefined
const task = useMemo(() => messages.at(0), [messages]) // leaving this less safe version here since if the first message is not a task, then the extension is in a bad state and needs to be debugged (see ClaudeDev.abort)
const task = useMemo(() => messages.at(0), [messages]) // leaving this less safe version here since if the first message is not a task, then the extension is in a bad state and needs to be debugged (see Cline.abort)
const modifiedMessages = useMemo(() => combineApiRequests(combineCommandSequences(messages.slice(1))), [messages])
// has to be after api_req_finished are all reduced into api_req_started messages
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])