Skip to content

Commit 88ca1b7

Browse files
committed
feat(devti): add module information to SketchRunContext #350
- Add moduleInfo parameter to SketchRunContext - Implement logic to detect and display module information for multi-module projects - Update sketch.vm templates to include module information
1 parent bf2ff08 commit 88ca1b7

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

core/src/main/kotlin/cc/unitmesh/devti/sketch/SketchRunContext.kt

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package cc.unitmesh.devti.sketch
33
import cc.unitmesh.devti.agent.tool.search.RipgrepSearcher
44
import cc.unitmesh.devti.gui.chat.message.ChatActionType
55
import cc.unitmesh.devti.gui.chat.ui.relativePath
6+
import cc.unitmesh.devti.mcp.host.Response
67
import cc.unitmesh.devti.provider.BuildSystemProvider
78
import cc.unitmesh.devti.provider.context.ChatContextItem
89
import cc.unitmesh.devti.provider.context.ChatContextProvider
@@ -17,6 +18,7 @@ import com.intellij.openapi.diagnostic.logger
1718
import com.intellij.openapi.editor.Editor
1819
import com.intellij.openapi.fileEditor.FileDocumentManager
1920
import com.intellij.openapi.fileEditor.FileEditorManager
21+
import com.intellij.openapi.module.ModuleManager
2022
import com.intellij.openapi.project.Project
2123
import com.intellij.openapi.project.ProjectManager
2224
import com.intellij.openapi.project.guessProjectDir
@@ -44,6 +46,7 @@ data class SketchRunContext(
4446
val buildTool: String = "",
4547
val searchTool: String = "localSearch",
4648
val rule: String = "",
49+
val moduleInfo: String = "",
4750
) : TemplateContext {
4851
companion object {
4952
suspend fun create(project: Project, myEditor: Editor?, input: String): SketchRunContext {
@@ -87,6 +90,8 @@ data class SketchRunContext(
8790
""
8891
}
8992

93+
val moduleInfo = moduleContext(project)
94+
9095
return SketchRunContext(
9196
currentFile = currentFile?.relativePath(project),
9297
currentElement = currentElement,
@@ -101,8 +106,37 @@ data class SketchRunContext(
101106
buildTool = buildTool,
102107
searchTool = lookupSearchTool(),
103108
rule = rule,
109+
moduleInfo = moduleInfo,
104110
)
105111
}
112+
113+
private val JAVA_ONE_PROJECT_SIZE_IN_IDEA = 2
114+
fun moduleContext(project: Project): String {
115+
val moduleManager = ModuleManager.getInstance(project)
116+
val allModules = moduleManager.modules.map { it.name }
117+
if (allModules.size <= JAVA_ONE_PROJECT_SIZE_IN_IDEA) {
118+
return ""
119+
}
120+
121+
val rootProjectName = allModules.minByOrNull { it.length } ?: return ""
122+
123+
val cleanedModules = allModules
124+
.filter { it != rootProjectName && !it.endsWith(".test") }
125+
.map { moduleName ->
126+
moduleName
127+
.removePrefix("$rootProjectName.")
128+
.removeSuffix(".main")
129+
}
130+
.distinct() // Remove duplicates after cleaning
131+
.filter { it.isNotEmpty() } // Remove any empty strings that might result
132+
133+
return if (cleanedModules.isNotEmpty()) {
134+
val modules = cleanedModules.joinToString(", ") { it }
135+
"- This project is a mono-repo projects, Please careful to create file in module. Here's modules: $modules"
136+
} else {
137+
""
138+
}
139+
}
106140
}
107141
}
108142

@@ -130,3 +164,4 @@ private fun workspace(myProject: Project? = null): String {
130164
val project = myProject ?: ProjectManager.getInstance().openProjects.firstOrNull()
131165
return project?.guessProjectDir()?.path ?: ""
132166
}
167+

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ Your main goal is to follow the USER's instructions at each message.
1818
- User's workspace context is: ${context.frameworkContext}
1919
- Current time is: ${context.time}
2020
${context.rule}
21+
${context.moduleInfo}
2122

2223
You have tools at your disposal to solve the coding task. We design a DSL call DevIn for you to call tools. If the USER's
2324
task is general or you already know the answer, just respond without calling tools.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ Here is basic information about the current workspace:
1515
- User's workspace context is: ${context.frameworkContext}
1616
- Current time is: ${context.time}
1717
${context.rule}
18+
${context.moduleInfo}
1819

1920
在编码之前,请确保您拥有足够的上下文信息。请遵循 DevIn <devin /> 指令编写代码,以节省用户的时间。请不要直接基于用户的问题进行编码,而是先通过
2021
tool calls 获取上下文信息来了解用户的代码库。

0 commit comments

Comments
 (0)