Skip to content

Commit 9012c1a

Browse files
committed
feat(observer): re-enable ExternalTaskAgentObserver and improve error handling #259
- Re-enable ExternalTaskAgentObserver in autodev-core.xml. - Format build issue prompt with code block in ExternalTaskAgentObserver. - Remove unused debugging method `getThreadTrace`. - Wrap error notification in `runInEdt` for thread safety in AgentObserver.
1 parent b571951 commit 9012c1a

File tree

3 files changed

+7
-16
lines changed

3 files changed

+7
-16
lines changed

core/src/233/main/resources/META-INF/autodev-core.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -277,7 +277,7 @@
277277
<toolchainFunctionProvider implementation="cc.unitmesh.devti.mcp.client.McpFunctionProvider"/>
278278

279279
<agentObserver implementation="cc.unitmesh.devti.observer.TestAgentObserver" />
280-
<!-- <agentObserver implementation="cc.unitmesh.devti.observer.ExternalTaskAgentObserver" />-->
280+
<agentObserver implementation="cc.unitmesh.devti.observer.ExternalTaskAgentObserver" />
281281
</extensions>
282282

283283
<actions>

core/src/main/kotlin/cc/unitmesh/devti/observer/ExternalTaskAgentObserver.kt

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -48,25 +48,13 @@ class ExternalTaskAgentObserver : AgentObserver, Disposable {
4848
exitCode: Int
4949
) {
5050
if (handler is ExternalSystemProcessHandler && exitCode != 0) {
51-
val prompt = "Help Me fix follow build issue:\n$globalBuffer"
51+
val prompt = "Help Me fix follow build issue:\n```bash\n$globalBuffer\n```\n"
5252
sendErrorNotification(project, prompt)
5353
}
5454
}
5555
})
5656
}
5757

58-
private fun getThreadTrace(thread: Thread, depth: Int): String { // debugging
59-
val buf = StringBuilder()
60-
val trace = thread.getStackTrace()
61-
var i = 0
62-
while (i < depth && i < trace.size) {
63-
val element = trace[i]
64-
buf.append("\tat ").append(element).append("\n")
65-
i++
66-
}
67-
return buf.toString()
68-
}
69-
7058
override fun dispose() {
7159
connection?.disconnect()
7260
}

core/src/main/kotlin/cc/unitmesh/devti/provider/observer/AgentObserver.kt

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ package cc.unitmesh.devti.provider.observer
22

33
import cc.unitmesh.devti.gui.chat.message.ChatActionType
44
import cc.unitmesh.devti.gui.sendToChatWindow
5+
import com.intellij.openapi.application.runInEdt
56
import com.intellij.openapi.extensions.ExtensionPointName
67
import com.intellij.openapi.project.Project
78

89
interface AgentObserver {
910
fun onRegister(project: Project)
1011

1112
fun sendErrorNotification(project: Project, prompt: String) {
12-
sendToChatWindow(project, ChatActionType.CHAT) { contentPanel, _ ->
13-
contentPanel.setInput(prompt)
13+
runInEdt {
14+
sendToChatWindow(project, ChatActionType.CHAT) { contentPanel, _ ->
15+
contentPanel.setInput(prompt)
16+
}
1417
}
1518
}
1619

0 commit comments

Comments
 (0)