Skip to content

Commit fc307a9

Browse files
committed
feat(devins-lang): refactor reorg conversation #100
1 parent 5f9bf7f commit fc307a9

File tree

2 files changed

+20
-16
lines changed

2 files changed

+20
-16
lines changed

docs/devins/orchestration.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,6 @@ In the following cases, AutoDev will auto execute:
3333
3. Use DevIns comment to flag, will run next script, like:
3434
3535
```devin
36-
[flow]script/flow.devin
36+
[flow]:script/flow.devin
3737
```
3838

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

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@ import org.jetbrains.kotlin.psi.psiUtil.startOffset
1919

2020
@Service(Service.Level.PROJECT)
2121
class DevInsProcessProcessor(val project: Project) {
22+
private val conversationService = project.service<DevInsConversationService>()
23+
2224
/**
2325
* This function takes a DevInFile as input and returns a list of PsiElements that are comments.
2426
* It iterates through the DevInFile and adds any comments it finds to the list.
@@ -39,48 +41,50 @@ class DevInsProcessProcessor(val project: Project) {
3941

4042
/**
4143
* Process the output of a script based on the exit code and flag comment.
44+
* If LLM returns a DevIn code, execute it.
4245
* If the exit code is not 0, attempts to fix the script with LLM.
4346
* If the exit code is 0 and there is a flag comment, process it.
4447
*
4548
* Flag comment format:
4649
* - [flow]:flowable.devin, means next step is flowable.devin
47-
* - [flow](result), means a handle with result
4850
*
4951
* @param output The output of the script
5052
* @param event The process event containing the exit code
5153
* @param scriptPath The path of the script file
5254
*/
5355
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)
5657

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))
6362
}
6463

6564
when {
6665
event.exitCode == 0 -> {
66+
val devInFile: DevInFile? = runReadAction { DevInFile.lookup(project, scriptPath) }
6767
val comment = lookupFlagComment(devInFile!!).firstOrNull() ?: return
6868
if (comment.startOffset == 0) {
6969
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)
7272
val newScript = DevInFile.lookup(project, nextScript) ?: return
73-
this.runTask(newScript)
73+
this.executeTask(newScript)
7474
}
7575
}
7676
}
7777
event.exitCode != 0 -> {
78-
project.service<DevInsConversationService>().tryFixWithLlm(scriptPath)
78+
conversationService.tryFixWithLlm(scriptPath)
7979
}
8080
}
8181
}
8282

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) {
8488
val compiledResult = DevInsCompiler(project, newScript).compile()
8589
val prompt = compiledResult.output
8690

@@ -96,7 +100,7 @@ class DevInsProcessProcessor(val project: Project) {
96100
* 1. We need to call LLM to get the task list
97101
* 2. According to the input and output to decide the next step
98102
*/
99-
fun createTasks(): List<DevInFile> {
103+
fun createAgentTasks(): List<DevInFile> {
100104
TODO()
101105
}
102106

0 commit comments

Comments
 (0)