Skip to content

Commit d330927

Browse files
committed
feat(observer): add enable observer setting and validation #259
- Add `enableObserver` checkbox to AutoDevCoderConfigurable UI. - Include `enableObserver` property in AutoDevCoderSettingService. - Validate `enableObserver` state in AgentObserver before sending notifications.
1 parent 0855f7d commit d330927

File tree

9 files changed

+26
-3
lines changed

9 files changed

+26
-3
lines changed

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

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package cc.unitmesh.devti.provider.observer
22

3+
import cc.unitmesh.devti.gui.AutoDevToolWindowFactory
34
import cc.unitmesh.devti.gui.chat.message.ChatActionType
4-
import cc.unitmesh.devti.gui.sendToChatWindow
5+
import cc.unitmesh.devti.settings.coder.coderSetting
56
import com.intellij.openapi.application.runInEdt
67
import com.intellij.openapi.extensions.ExtensionPointName
78
import com.intellij.openapi.project.Project
@@ -10,9 +11,13 @@ interface AgentObserver {
1011
fun onRegister(project: Project)
1112

1213
fun sendErrorNotification(project: Project, prompt: String) {
14+
if (prompt.isBlank()) return
15+
if (project.coderSetting.state.enableObserver == false) return
16+
1317
runInEdt {
14-
sendToChatWindow(project, ChatActionType.CHAT) { contentPanel, _ ->
15-
contentPanel.setInput(prompt)
18+
// or sendToChatWindow ?
19+
AutoDevToolWindowFactory.sendToSketchToolWindow(project, ChatActionType.CHAT) { ui, _ ->
20+
ui.setInput(prompt)
1621
}
1722
}
1823
}

core/src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderConfigurable.kt

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
2121
private val inEditorCompletionCheckBox = JCheckBox()
2222
private val noChatHistoryCheckBox = JCheckBox()
2323
private val enableMcpServerCheckBox = JCheckBox()
24+
private val enableObserver = JCheckBox()
2425
private val teamPromptsField = JTextField()
2526
private val trimCodeBeforeSend = JCheckBox()
2627

@@ -65,6 +66,15 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
6566
)
6667
}
6768

69+
row(jLabel("settings.autodev.coder.enableObserver")) {
70+
fullWidthCell(enableObserver)
71+
.bind(
72+
componentGet = { it.isSelected },
73+
componentSet = { component, value -> component.isSelected = value },
74+
prop = state::enableObserver.toMutableProperty()
75+
)
76+
}
77+
6878
row(jLabel("settings.autodev.coder.trimCodeBeforeSend")) {
6979
fullWidthCell(trimCodeBeforeSend)
7080
.bind(
@@ -111,6 +121,7 @@ class AutoDevCoderConfigurable(private val project: Project) : BoundConfigurable
111121
it.trimCodeBeforeSend = state.trimCodeBeforeSend
112122
it.teamPromptsDir = state.teamPromptsDir
113123
it.enableExportAsMcpServer = state.enableExportAsMcpServer
124+
it.enableObserver = state.enableObserver
114125
}
115126
}
116127
}

core/src/main/kotlin/cc/unitmesh/devti/settings/coder/AutoDevCoderSettingService.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class AutoDevCoderSettingService(
2323
var recordingInLocal by property(false)
2424
var disableAdvanceContext by property(false)
2525
var enableExportAsMcpServer by property(false)
26+
var enableObserver by property(true)
2627
var inEditorCompletion by property(false)
2728
var noChatHistory by property(false)
2829
var trimCodeBeforeSend by property(false)

core/src/main/resources/genius/en/code/plan.devin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ $context.toolList
3434
instead of saying 'I need to use the edit file tool to edit your file', just
3535
say 'I will edit your file'.
3636
5. Before calling each tool, first explain to the USER why you are calling it.
37+
6. Make sure every write operation (like `patch`) is with standalone `<devin />` tag.
3738
</tool_calling>
3839

3940
Here is the rule you should follow:

core/src/main/resources/genius/en/code/sketch.vm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ $context.toolList
4040
instead of saying 'I need to use the edit file tool to edit your file', just
4141
say 'I will edit your file'.
4242
5. Before calling each tool, first explain to the USER why you are calling it.
43+
6. Make sure every write operation (like `patch`) is with standalone `<devin />` tag.
4344
</tool_calling>
4445

4546
Here is an example output to the USER:

core/src/main/resources/genius/zh/code/plan.devin

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ $context.toolList
3434
instead of saying 'I need to use the edit file tool to edit your file', just
3535
say 'I will edit your file'.
3636
5. Before calling each tool, first explain to the USER why you are calling it.
37+
6. Make sure every write operation (like `patch`) is with standalone `<devin />` tag.
3738
</tool_calling>
3839

3940
Here is the rule you should follow:

core/src/main/resources/genius/zh/code/sketch.vm

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ $context.toolList
4040
instead of saying 'I need to use the edit file tool to edit your file', just
4141
say 'I will edit your file'.
4242
5. Before calling each tool, first explain to the USER why you are calling it.
43+
6. Make sure every write operation (like `patch`) is with standalone `<devin />` tag.
4344
</tool_calling>
4445

4546
Here is an example output to the USER:

core/src/main/resources/messages/AutoDevBundle_en.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,7 @@ settings.autodev.coder.disableAdvanceContext.tips=like framework context, langua
9191
settings.autodev.coder.inEditorCompletion=Completion in Editor
9292
settings.autodev.coder.noChatHistory=No Chat History
9393
settings.autodev.coder.enableExportAsMcpServer=Enable Export as MCP Server
94+
settings.autodev.coder.enableObserver=Enable Observer Agent
9495
settings.autodev.coder.explainCode=Explain code
9596
settings.autodev.coder.refactorCode=Refactor code
9697
settings.autodev.coder.fixIssueCode=Fix issue

core/src/main/resources/messages/AutoDevBundle_zh.properties

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,7 @@ settings.autodev.coder.disableAdvanceContext.tips=如框架上下文、语言上
9595
settings.autodev.coder.inEditorCompletion=编辑器中的实时补全
9696
settings.autodev.coder.noChatHistory=没有聊天记录
9797
settings.autodev.coder.enableExportAsMcpServer=允许作为 MCP 服务器输出
98+
settings.autodev.coder.enableObserver=使用 Observer 模式
9899
settings.autodev.coder.explainCode=解释代码
99100
settings.autodev.coder.refactorCode=重构代码
100101
settings.autodev.coder.fixIssueCode=修复问题

0 commit comments

Comments
 (0)