mirror of
https://github.com/pacnpal/Roo-Code.git
synced 2025-12-20 12:21:13 -05:00
Refactor ClaudeDev
This commit is contained in:
@@ -206,9 +206,9 @@ export class Cline {
|
|||||||
text?: string,
|
text?: string,
|
||||||
partial?: boolean
|
partial?: boolean
|
||||||
): Promise<{ response: ClaudeAskResponse; text?: string; images?: string[] }> {
|
): 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) {
|
if (this.abort) {
|
||||||
throw new Error("ClaudeDev instance aborted")
|
throw new Error("Cline instance aborted")
|
||||||
}
|
}
|
||||||
let askTs: number
|
let askTs: number
|
||||||
if (partial !== undefined) {
|
if (partial !== undefined) {
|
||||||
@@ -304,7 +304,7 @@ export class Cline {
|
|||||||
|
|
||||||
async say(type: ClaudeSay, text?: string, images?: string[], partial?: boolean): Promise<undefined> {
|
async say(type: ClaudeSay, text?: string, images?: string[], partial?: boolean): Promise<undefined> {
|
||||||
if (this.abort) {
|
if (this.abort) {
|
||||||
throw new Error("ClaudeDev instance aborted")
|
throw new Error("Cline instance aborted")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (partial !== undefined) {
|
if (partial !== undefined) {
|
||||||
@@ -374,7 +374,7 @@ export class Cline {
|
|||||||
|
|
||||||
private async startTask(task?: string, images?: string[]): Promise<void> {
|
private async startTask(task?: string, images?: string[]): Promise<void> {
|
||||||
// conversationHistory (for API) and claudeMessages (for webview) need to be in sync
|
// 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.claudeMessages = []
|
||||||
this.apiConversationHistory = []
|
this.apiConversationHistory = []
|
||||||
await this.providerRef.deref()?.postStateToWebview()
|
await this.providerRef.deref()?.postStateToWebview()
|
||||||
@@ -743,7 +743,7 @@ export class Cline {
|
|||||||
|
|
||||||
async presentAssistantMessage() {
|
async presentAssistantMessage() {
|
||||||
if (this.abort) {
|
if (this.abort) {
|
||||||
throw new Error("ClaudeDev instance aborted")
|
throw new Error("Cline instance aborted")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.presentAssistantMessageLocked) {
|
if (this.presentAssistantMessageLocked) {
|
||||||
@@ -1554,7 +1554,7 @@ export class Cline {
|
|||||||
includeFileDetails: boolean = false
|
includeFileDetails: boolean = false
|
||||||
): Promise<boolean> {
|
): Promise<boolean> {
|
||||||
if (this.abort) {
|
if (this.abort) {
|
||||||
throw new Error("ClaudeDev instance aborted")
|
throw new Error("Cline instance aborted")
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.consecutiveMistakeCount >= 3) {
|
if (this.consecutiveMistakeCount >= 3) {
|
||||||
@@ -1738,7 +1738,7 @@ export class Cline {
|
|||||||
|
|
||||||
// need to call here in case the stream was aborted
|
// need to call here in case the stream was aborted
|
||||||
if (this.abort) {
|
if (this.abort) {
|
||||||
throw new Error("ClaudeDev instance aborted")
|
throw new Error("Cline instance aborted")
|
||||||
}
|
}
|
||||||
|
|
||||||
this.didCompleteReadingStream = true
|
this.didCompleteReadingStream = true
|
||||||
|
|||||||
@@ -56,8 +56,8 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
})
|
})
|
||||||
)
|
)
|
||||||
|
|
||||||
const openClaudeDevInNewTab = async () => {
|
const openClineInNewTab = async () => {
|
||||||
outputChannel.appendLine("Opening Claude Dev in new tab")
|
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)
|
// (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
|
// https://github.com/microsoft/vscode-extension-samples/blob/main/webview-sample/src/extension.ts
|
||||||
const tabProvider = new ClineProvider(context, outputChannel)
|
const tabProvider = new ClineProvider(context, outputChannel)
|
||||||
@@ -89,8 +89,8 @@ export function activate(context: vscode.ExtensionContext) {
|
|||||||
await vscode.commands.executeCommand("workbench.action.lockEditorGroup")
|
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.popoutButtonTapped", openClineInNewTab))
|
||||||
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.openInNewTab", openClaudeDevInNewTab))
|
context.subscriptions.push(vscode.commands.registerCommand("claude-dev.openInNewTab", openClineInNewTab))
|
||||||
|
|
||||||
context.subscriptions.push(
|
context.subscriptions.push(
|
||||||
vscode.commands.registerCommand("claude-dev.settingsButtonTapped", () => {
|
vscode.commands.registerCommand("claude-dev.settingsButtonTapped", () => {
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ interface AnnouncementProps {
|
|||||||
hideAnnouncement: () => void
|
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) => {
|
const Announcement = ({ version, hideAnnouncement }: AnnouncementProps) => {
|
||||||
return (
|
return (
|
||||||
|
|||||||
@@ -31,7 +31,7 @@ const ChatView = ({ isHidden, showAnnouncement, hideAnnouncement, showHistoryVie
|
|||||||
const { version, claudeMessages: messages, taskHistory, apiConfiguration } = useExtensionState()
|
const { version, claudeMessages: messages, taskHistory, apiConfiguration } = useExtensionState()
|
||||||
|
|
||||||
//const task = messages.length > 0 ? (messages[0].say === "task" ? messages[0] : undefined) : undefined) : undefined
|
//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])
|
const modifiedMessages = useMemo(() => combineApiRequests(combineCommandSequences(messages.slice(1))), [messages])
|
||||||
// has to be after api_req_finished are all reduced into api_req_started messages
|
// has to be after api_req_finished are all reduced into api_req_started messages
|
||||||
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])
|
const apiMetrics = useMemo(() => getApiMetrics(modifiedMessages), [modifiedMessages])
|
||||||
|
|||||||
Reference in New Issue
Block a user