@@ -19,6 +19,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
19
19
20
20
@Service(Service .Level .PROJECT )
21
21
class DevInsProcessProcessor (val project : Project ) {
22
+ private val conversationService = project.service<DevInsConversationService >()
23
+
22
24
/* *
23
25
* This function takes a DevInFile as input and returns a list of PsiElements that are comments.
24
26
* It iterates through the DevInFile and adds any comments it finds to the list.
@@ -39,48 +41,50 @@ class DevInsProcessProcessor(val project: Project) {
39
41
40
42
/* *
41
43
* Process the output of a script based on the exit code and flag comment.
44
+ * If LLM returns a DevIn code, execute it.
42
45
* If the exit code is not 0, attempts to fix the script with LLM.
43
46
* If the exit code is 0 and there is a flag comment, process it.
44
47
*
45
48
* Flag comment format:
46
49
* - [flow]:flowable.devin, means next step is flowable.devin
47
- * - [flow](result), means a handle with result
48
50
*
49
51
* @param output The output of the script
50
52
* @param event The process event containing the exit code
51
53
* @param scriptPath The path of the script file
52
54
*/
53
55
fun process (output : String , event : ProcessEvent , scriptPath : String ) {
54
- val devInFile: DevInFile ? = runReadAction { DevInFile .lookup(project, scriptPath) }
55
- project.service<DevInsConversationService >().updateIdeOutput(scriptPath, output)
56
+ conversationService.updateIdeOutput(scriptPath, output)
56
57
57
- val llmResponse = project.service<DevInsConversationService >().getLlmResponse(scriptPath)
58
- val code = Code .parse(llmResponse)
59
- if (code.language == DevInLanguage .INSTANCE ) {
60
- val devInCode = code.text
61
- val file = DevInFile .fromString(project, devInCode)
62
- runTask(file)
58
+ val code = Code .parse(conversationService.getLlmResponse(scriptPath))
59
+ val isDevInCode = code.language == DevInLanguage .INSTANCE
60
+ if (isDevInCode) {
61
+ executeTask(DevInFile .fromString(project, code.text))
63
62
}
64
63
65
64
when {
66
65
event.exitCode == 0 -> {
66
+ val devInFile: DevInFile ? = runReadAction { DevInFile .lookup(project, scriptPath) }
67
67
val comment = lookupFlagComment(devInFile!! ).firstOrNull() ? : return
68
68
if (comment.startOffset == 0 ) {
69
69
val text = comment.text
70
- if (text.startsWith(" [flow]" )) {
71
- val nextScript = text.substring(6 )
70
+ if (text.startsWith(" [flow]: " )) {
71
+ val nextScript = text.substring(7 )
72
72
val newScript = DevInFile .lookup(project, nextScript) ? : return
73
- this .runTask (newScript)
73
+ this .executeTask (newScript)
74
74
}
75
75
}
76
76
}
77
77
event.exitCode != 0 -> {
78
- project.service< DevInsConversationService >() .tryFixWithLlm(scriptPath)
78
+ conversationService .tryFixWithLlm(scriptPath)
79
79
}
80
80
}
81
81
}
82
82
83
- fun runTask (newScript : DevInFile ) {
83
+ /* *
84
+ * This function is responsible for running a task with a new script.
85
+ * @param newScript The new script to be run.
86
+ */
87
+ fun executeTask (newScript : DevInFile ) {
84
88
val compiledResult = DevInsCompiler (project, newScript).compile()
85
89
val prompt = compiledResult.output
86
90
@@ -96,7 +100,7 @@ class DevInsProcessProcessor(val project: Project) {
96
100
* 1. We need to call LLM to get the task list
97
101
* 2. According to the input and output to decide the next step
98
102
*/
99
- fun createTasks (): List <DevInFile > {
103
+ fun createAgentTasks (): List <DevInFile > {
100
104
TODO ()
101
105
}
102
106
0 commit comments