Skip to content

Commit 6bcdf15

Browse files
committed
fix(devins-lang): add basic handle for exitCode=-1 to recall function
- Improve file writing performance by optimizing the process termination listener and adding a new input field for DevInsCompiledResult. This will enhance the overall efficiency of the DevIns language compiler.
1 parent ff38ea9 commit 6bcdf15

File tree

4 files changed

+56
-5
lines changed

4 files changed

+56
-5
lines changed

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiledResult.kt

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ package cc.unitmesh.devti.language.compiler
33
import cc.unitmesh.devti.agent.model.CustomAgentConfig
44

55
data class DevInsCompiledResult(
6+
var input: String = "",
67
var output: String = "",
78
var isLocalCommand: Boolean = false,
89
var hasError: Boolean = false,
910
var workingAgent: CustomAgentConfig? = null
10-
)
11+
) {
12+
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/compiler/DevInsCompiler.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ class DevInsCompiler(
3434
* Todo: build AST tree, then compile
3535
*/
3636
fun compile(): DevInsCompiledResult {
37+
result.input = file.text
3738
file.children.forEach {
3839
when (it.elementType) {
3940
DevInTypes.TEXT_SEGMENT -> output.append(it.text)

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/DevInsRunConfigurationProfileState.kt

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import com.intellij.openapi.components.service
2929
import com.intellij.openapi.project.Project
3030
import com.intellij.openapi.util.Key
3131
import com.intellij.ui.components.panels.NonOpaquePanel
32-
import kotlinx.coroutines.flow.*
32+
import kotlinx.coroutines.flow.Flow
3333
import kotlinx.coroutines.launch
3434
import kotlinx.coroutines.runBlocking
3535
import java.awt.BorderLayout
@@ -49,12 +49,18 @@ open class DevInsRunConfigurationProfileState(
4949
val sb = StringBuilder()
5050

5151
processHandler.addProcessListener(object : ProcessAdapter() {
52+
var result = ""
5253
override fun processTerminated(event: ProcessEvent) {
5354
super.processTerminated(event)
5455

5556
ApplicationManager.getApplication().messageBus
5657
.syncPublisher(DevInsRunListener.TOPIC)
57-
.runFinish(sb.toString(), event, configuration.getScriptPath())
58+
.runFinish(result, event, configuration.getScriptPath())
59+
}
60+
61+
override fun onTextAvailable(event: ProcessEvent, outputType: Key<*>) {
62+
super.onTextAvailable(event, outputType)
63+
result = sb.toString()
5864
}
5965
})
6066

@@ -108,6 +114,7 @@ open class DevInsRunConfigurationProfileState(
108114
}
109115

110116
console.print("\n--------------------\n", ConsoleViewContentType.NORMAL_OUTPUT)
117+
111118
// throw error if contains any <DevInsError>
112119
if (output.contains("<DevInsError>")) {
113120
processHandler.exitWithError()
@@ -166,7 +173,7 @@ open class DevInsRunConfigurationProfileState(
166173
LLMCoroutineScope.scope(myProject).launch {
167174
val llmResult = StringBuilder()
168175
runBlocking {
169-
llm.stream(output, "").collect {
176+
llm.stream(output, "", false).collect {
170177
llmResult.append(it)
171178
console.print(it, ConsoleViewContentType.NORMAL_OUTPUT)
172179
}

exts/devins-lang/src/main/kotlin/cc/unitmesh/devti/language/run/flow/DevInsConversations.kt

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,18 @@
11
package cc.unitmesh.devti.language.run.flow
22

3+
import cc.unitmesh.devti.gui.chat.ChatActionType
4+
import cc.unitmesh.devti.gui.sendToChatWindow
35
import cc.unitmesh.devti.language.compiler.DevInsCompiledResult
6+
import cc.unitmesh.devti.llms.LLMProvider
7+
import cc.unitmesh.devti.llms.LlmFactory
8+
import cc.unitmesh.devti.provider.ContextPrompter
49
import com.intellij.openapi.components.Service
510
import com.intellij.openapi.project.Project
611

712
@Service(Service.Level.PROJECT)
813
class DevInsConversationService(val project: Project) {
14+
private val llm: LLMProvider = LlmFactory.instance.create(project)
15+
916
/**
1017
* The cached conversations
1118
*/
@@ -63,13 +70,47 @@ class DevInsConversationService(val project: Project) {
6370

6471
conversation.hadReRun = true
6572
// call llm again to re-run
73+
74+
val prompt = StringBuilder()
75+
76+
// todo: refactor to DevIn template file
77+
if (conversation.compiledResult.isLocalCommand) {
78+
prompt.append("You are a top software developer in the world, which can help me to fix the issue.\n")
79+
prompt.append("When I use DevIn language and compile the script, I got an error, can you help me to fix it?\n")
80+
prompt.append("Origin DevIn script:\n")
81+
prompt.append("```devin\n")
82+
prompt.append(conversation.compiledResult.input)
83+
prompt.append("```\n")
84+
85+
prompt.append("The Compile Result:\n")
86+
prompt.append("####\n")
87+
prompt.append(conversation.compiledResult.output)
88+
prompt.append("####\n")
89+
}
90+
91+
prompt.append("""
92+
Here is the run result, can you help me to fix it?
93+
Run result:
94+
####
95+
${conversation.ideOutput}
96+
####
97+
""".trimIndent()
98+
)
99+
100+
val finalPrompt = prompt.toString()
101+
sendToChatWindow(project, ChatActionType.CHAT) { panel, service ->
102+
service.handlePromptAndResponse(panel, object : ContextPrompter() {
103+
override fun displayPrompt(): String = finalPrompt
104+
override fun requestPrompt(): String = finalPrompt
105+
}, null, true)
106+
}
66107
}
67108
}
68109

69110

70111
data class DevInsConversation(
71112
val scriptPath: String,
72-
val result: DevInsCompiledResult,
113+
val compiledResult: DevInsCompiledResult,
73114
val llmResponse: String,
74115
val ideOutput: String,
75116
val messages: MutableList<cc.unitmesh.devti.llms.custom.Message> = mutableListOf(),

0 commit comments

Comments
 (0)