Răsfoiți Sursa

Merge pull request #4362 from Kilo-Org/add-back-separate-extension/cli-handling

Igor Šćekić 2 luni în urmă
părinte
comite
2174c6e817

+ 6 - 0
.changeset/giant-spoons-jump.md

@@ -0,0 +1,6 @@
+---
+"@kilocode/cli": patch
+"kilo-code": patch
+---
+
+extract an extension message handler for extension/cli reuse

+ 18 - 0
cli/src/state/atoms/effects.ts

@@ -34,6 +34,7 @@ import {
 import { validateModelOnRouterModelsUpdateAtom } from "./modelValidation.js"
 import { validateModeOnCustomModesUpdateAtom } from "./modeValidation.js"
 import { logs } from "../../services/logs.js"
+import { SessionManager } from "../../../../src/shared/kilocode/cli-sessions/core/SessionManager.js"
 
 /**
  * Message buffer to handle race conditions during initialization
@@ -175,6 +176,23 @@ export const messageHandlerEffectAtom = atom(null, (get, set, message: Extension
 			return
 		}
 
+		// NOTE: Copied from ClineProvider - make sure the two match.
+		if (message.type === "apiMessagesSaved" && message.payload) {
+			const [taskId, filePath] = message.payload as [string, string]
+
+			SessionManager.init().handleFileUpdate(taskId, "apiConversationHistoryPath", filePath)
+		} else if (message.type === "taskMessagesSaved" && message.payload) {
+			const [taskId, filePath] = message.payload as [string, string]
+
+			SessionManager.init().handleFileUpdate(taskId, "uiMessagesPath", filePath)
+		} else if (message.type === "taskMetadataSaved" && message.payload) {
+			const [taskId, filePath] = message.payload as [string, string]
+
+			SessionManager.init().handleFileUpdate(taskId, "taskMetadataPath", filePath)
+		} else if (message.type === "currentCheckpointUpdated") {
+			SessionManager.init().doSync()
+		}
+
 		// Handle different message types
 		switch (message.type) {
 			case "state":

+ 15 - 14
src/core/webview/ClineProvider.ts

@@ -1149,23 +1149,24 @@ ${prompt}
 	}
 
 	public async postMessageToWebview(message: ExtensionMessage) {
-		// kilocode_change start
-		if (message.type === "apiMessagesSaved" && message.payload) {
-			const [taskId, filePath] = message.payload as [string, string]
+		// NOTE: Changing this? Update effects.ts in the cli too.
+		kilo_execIfExtension(() => {
+			if (message.type === "apiMessagesSaved" && message.payload) {
+				const [taskId, filePath] = message.payload as [string, string]
 
-			SessionManager.init().handleFileUpdate(taskId, "apiConversationHistoryPath", filePath)
-		} else if (message.type === "taskMessagesSaved" && message.payload) {
-			const [taskId, filePath] = message.payload as [string, string]
+				SessionManager.init().handleFileUpdate(taskId, "apiConversationHistoryPath", filePath)
+			} else if (message.type === "taskMessagesSaved" && message.payload) {
+				const [taskId, filePath] = message.payload as [string, string]
 
-			SessionManager.init().handleFileUpdate(taskId, "uiMessagesPath", filePath)
-		} else if (message.type === "taskMetadataSaved" && message.payload) {
-			const [taskId, filePath] = message.payload as [string, string]
+				SessionManager.init().handleFileUpdate(taskId, "uiMessagesPath", filePath)
+			} else if (message.type === "taskMetadataSaved" && message.payload) {
+				const [taskId, filePath] = message.payload as [string, string]
 
-			SessionManager.init().handleFileUpdate(taskId, "taskMetadataPath", filePath)
-		} else if (message.type === "currentCheckpointUpdated") {
-			SessionManager.init().doSync()
-		}
-		// kilocode_change end
+				SessionManager.init().handleFileUpdate(taskId, "taskMetadataPath", filePath)
+			} else if (message.type === "currentCheckpointUpdated") {
+				SessionManager.init().doSync()
+			}
+		})
 
 		await this.view?.webview.postMessage(message)
 	}