Skip to content

Commit 94606e2

Browse files
committed
feat(agent): refactor agent system with DevIns integration #379
- Remove deprecated AgentTool and rename ShireConstants to DevInsConstants - Add DevInsAgentToolCollector for unified agent management - Default agentic property to false in HobbitHole - Add new agent icons and completion improvements
1 parent f47e696 commit 94606e2

File tree

13 files changed

+136
-45
lines changed

13 files changed

+136
-45
lines changed

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,11 @@
225225
interface="cc.unitmesh.devti.mcp.host.McpTool"
226226
dynamic="true"/>
227227

228+
<!-- DevIns Tool -->
229+
<extensionPoint qualifiedName="cc.unitmesh.devInsAgentTool"
230+
interface="cc.unitmesh.devti.provider.DevInsAgentToolCollector"
231+
dynamic="true"/>
232+
228233
<extensionPoint qualifiedName="cc.unitmesh.agentObserver"
229234
interface="cc.unitmesh.devti.provider.observer.AgentObserver"
230235
dynamic="true"/>

core/src/main/kotlin/cc/unitmesh/devti/AutoDevIcons.kt

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,4 +103,10 @@ object AutoDevIcons {
103103

104104
@JvmField
105105
val MAGIC: Icon = IconLoader.getIcon("/icons/magic.svg", AutoDevIcons::class.java)
106+
107+
@JvmField
108+
val CLOUD_AGENT: Icon = IconLoader.getIcon("/icons/cloud-agent.svg", AutoDevIcons::class.java)
109+
110+
@JvmField
111+
val LOCAL_AGENT: Icon = IconLoader.getIcon("/icons/local-agent.svg", AutoDevIcons::class.java)
106112
}

core/src/main/kotlin/cc/unitmesh/devti/agent/custom/model/CustomAgentConfig.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ data class CustomAgentConfig(
5656
val auth: CustomAgentAuth? = null,
5757
val defaultTimeout: Long = 10,
5858
val enabled: Boolean = true,
59+
var isFromDevIns: Boolean = false,
5960
) {
6061
var state: CustomAgentState = CustomAgentState.START
6162

core/src/main/kotlin/cc/unitmesh/devti/agent/tool/AgentTool.kt

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ data class AgentTool(
1010
val isMcp: Boolean = false,
1111
val completion: String = "",
1212
val mcpGroup: String = "",
13+
val isDevIns: Boolean = false,
14+
val devInsPath: String = "",
1315
) : Tool {
1416
override fun toString(): String {
1517
val string = if (description.isEmpty()) "" else """desc: $description"""
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package cc.unitmesh.devti.provider
2+
3+
import cc.unitmesh.devti.agent.tool.AgentTool
4+
import com.intellij.openapi.extensions.ExtensionPointName
5+
import com.intellij.openapi.project.Project
6+
7+
interface DevInsAgentToolCollector {
8+
fun collect(project: Project): List<AgentTool>
9+
10+
suspend fun execute(project: Project, agentName: String, input: String): String?
11+
12+
companion object {
13+
private val EP_NAME: ExtensionPointName<DevInsAgentToolCollector> =
14+
ExtensionPointName("cc.unitmesh.devInsAgentTool")
15+
16+
fun all(project: Project): List<AgentTool> {
17+
return EP_NAME.extensionList.flatMap { it.collect(project) }
18+
}
19+
}
20+
}
Lines changed: 15 additions & 0 deletions
Loading
Lines changed: 15 additions & 0 deletions
Loading

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/ast/HobbitHole.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ open class HobbitHole(
373373
val interaction = frontMatterMap[INTERACTION]?.value as? String ?: ""
374374
val actionLocation = frontMatterMap[ACTION_LOCATION]?.value as? String ?: DevInsActionLocation.default()
375375
val enabled = frontMatterMap[ENABLED]?.value as? Boolean ?: true
376-
val agentic = frontMatterMap[AGENTIC]?.value as? Boolean ?: true
376+
val agentic = frontMatterMap[AGENTIC]?.value as? Boolean ?: false
377377
val model = frontMatterMap[MODEL]?.value as? String
378378

379379
val shortcut = (frontMatterMap[SHORTCUT]?.value as? String)?.let {

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/completion/provider/CustomAgentCompletion.kt

Lines changed: 37 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
package cc.unitmesh.devti.language.completion.provider
22

3+
import cc.unitmesh.devti.AutoDevIcons
34
import cc.unitmesh.devti.agent.custom.model.CustomAgentConfig
45
import cc.unitmesh.devti.gui.AutoDevToolWindowFactory.AutoDevToolUtil
56
import cc.unitmesh.devti.gui.chat.NormalChatCodingPanel
7+
import cc.unitmesh.devti.provider.DevInsAgentToolCollector
68
import com.intellij.codeInsight.completion.CompletionParameters
79
import com.intellij.codeInsight.completion.CompletionProvider
810
import com.intellij.codeInsight.completion.CompletionResultSet
@@ -20,18 +22,44 @@ class CustomAgentCompletion : CompletionProvider<CompletionParameters>() {
2022
configs.forEach { config ->
2123
result.addElement(
2224
LookupElementBuilder.create(config.name)
23-
.withInsertHandler { context, _ ->
24-
context.document.insertString(context.tailOffset, " ")
25-
context.editor.caretModel.moveCaretRelatively(1, 0, false, true, false)
25+
.withIcon(AutoDevIcons.CLOUD_AGENT)
26+
.withInsertHandler { context, _ ->
27+
context.document.insertString(context.tailOffset, " ")
28+
context.editor.caretModel.moveCaretRelatively(1, 0, false, true, false)
2629

27-
val toolWindow = ToolWindowManager.getInstance(context.project).getToolWindow(AutoDevToolUtil.ID)
28-
toolWindow?.contentManager?.contents?.map { it.component }?.forEach {
29-
if (it is NormalChatCodingPanel) {
30-
it.selectAgent(config)
30+
val toolWindow =
31+
ToolWindowManager.getInstance(context.project).getToolWindow(AutoDevToolUtil.ID)
32+
toolWindow?.contentManager?.contents?.map { it.component }?.forEach {
33+
if (it is NormalChatCodingPanel) {
34+
it.selectAgent(config)
35+
}
3136
}
3237
}
33-
}
34-
.withTypeText(config.description, true))
38+
.withTypeText(config.description, true))
39+
}
40+
41+
val project = parameters.originalFile.project
42+
val devInsAgent = DevInsAgentToolCollector.all(project).map {
43+
CustomAgentConfig(name = it.name, description = it.description, isFromDevIns = true)
44+
}
45+
46+
devInsAgent.forEach { config ->
47+
result.addElement(
48+
LookupElementBuilder.create(config.name)
49+
.withIcon(AutoDevIcons.LOCAL_AGENT)
50+
.withInsertHandler { context, _ ->
51+
context.document.insertString(context.tailOffset, " ")
52+
context.editor.caretModel.moveCaretRelatively(1, 0, false, true, false)
53+
54+
val toolWindow =
55+
ToolWindowManager.getInstance(context.project).getToolWindow(AutoDevToolUtil.ID)
56+
toolWindow?.contentManager?.contents?.map { it.component }?.forEach {
57+
if (it is NormalChatCodingPanel) {
58+
it.selectAgent(config)
59+
}
60+
}
61+
}
62+
.withTypeText(config.description, true))
3563
}
3664
}
3765
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/provider/AgentTool.kt

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)