From 9e55bd1d97de1c5ce2e9151a65c05cb7950ab29f Mon Sep 17 00:00:00 2001 From: Phodal Huang Date: Sat, 29 Jun 2024 20:26:20 +0800 Subject: [PATCH] feat(runners): add HobbitHole to ShireRunner classes #24 The ShireRunner classes now include a HobbitHole parameter. This change affects the CustomRemoteAgentRunner and ShireDefaultRunner classes. The HobbitHole parameter is used to handle different types of interactions in the handleResult function. --- .../run/ShireRunConfigurationProfileState.kt | 4 ++-- .../run/runner/CustomRemoteAgentRunner.kt | 4 +++- .../shirelang/run/runner/ShireDefaultRunner.kt | 5 +++-- .../phodal/shirelang/run/runner/ShireRunner.kt | 17 +++++++++++++++++ 4 files changed, 25 insertions(+), 5 deletions(-) diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt index b4e8f47a6..821462399 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/ShireRunConfigurationProfileState.kt @@ -99,11 +99,11 @@ open class ShireRunConfigurationProfileState( val agent = compileResult.executeAgent val shireRunner: ShireRunner = when { agent != null -> { - CustomRemoteAgentRunner(myProject, configuration, console!!, processHandler, promptText, agent) + CustomRemoteAgentRunner(myProject, configuration, console!!, processHandler, promptText, hobbitHole, agent) } else -> { val isLocalMode = compileResult.isLocalCommand - ShireDefaultRunner(myProject, configuration, console!!, processHandler, promptText, isLocalMode) + ShireDefaultRunner(myProject, configuration, console!!, processHandler, promptText, hobbitHole, isLocalMode) } } diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/CustomRemoteAgentRunner.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/CustomRemoteAgentRunner.kt index 48a3b45d9..f35d071ef 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/CustomRemoteAgentRunner.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/CustomRemoteAgentRunner.kt @@ -8,6 +8,7 @@ import com.intellij.openapi.project.Project import com.phodal.shirecore.agent.CustomAgent import com.phodal.shire.agent.CustomAgentExecutor import com.phodal.shirelang.ShireBundle +import com.phodal.shirelang.compiler.hobbit.HobbitHole import com.phodal.shirelang.run.ShireConfiguration import com.phodal.shirelang.run.flow.ShireConversationService import com.phodal.shirelang.utils.ShireCoroutineScope @@ -21,8 +22,9 @@ class CustomRemoteAgentRunner( override val console: ConsoleViewWrapperBase, override val processHandler: ProcessHandler, override val prompt: String, + override val hole: HobbitHole?, private val agent: CustomAgent, -) : ShireRunner(configuration, processHandler, console, myProject, prompt) { +) : ShireRunner(configuration, processHandler, console, myProject, hole, prompt) { override fun execute(postFunction: (response: String) -> Unit) { ApplicationManager.getApplication().invokeLater { val stringFlow: Flow? = CustomAgentExecutor(project = myProject).execute(prompt, agent) diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt index 5b48d6b16..a91e55756 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireDefaultRunner.kt @@ -8,9 +8,9 @@ import com.intellij.openapi.application.ModalityState import com.intellij.openapi.project.Project import com.phodal.shire.llm.LlmProvider import com.phodal.shirelang.ShireBundle +import com.phodal.shirelang.compiler.hobbit.HobbitHole import com.phodal.shirelang.run.ShireConfiguration import com.phodal.shirelang.run.flow.ShireConversationService -import com.phodal.shirelang.utils.ShireCoroutineScope import kotlinx.coroutines.* class ShireDefaultRunner( @@ -19,8 +19,9 @@ class ShireDefaultRunner( override val console: ConsoleViewWrapperBase, override val processHandler: ProcessHandler, override val prompt: String, + override val hole: HobbitHole?, private val isLocalMode: Boolean, -) : ShireRunner(configuration, processHandler, console, myProject, prompt) { +) : ShireRunner(configuration, processHandler, console, myProject, hole, prompt) { override fun execute(postFunction: (response: String) -> Unit) { ApplicationManager.getApplication().invokeLater({ if (isLocalMode) { diff --git a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt index 99f7e9b25..21ce5e5ff 100644 --- a/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt +++ b/shirelang/src/main/kotlin/com/phodal/shirelang/run/runner/ShireRunner.kt @@ -3,6 +3,8 @@ package com.phodal.shirelang.run.runner import com.intellij.execution.console.ConsoleViewWrapperBase import com.intellij.execution.process.ProcessHandler import com.intellij.openapi.project.Project +import com.phodal.shirecore.agent.InteractionType +import com.phodal.shirelang.compiler.hobbit.HobbitHole import com.phodal.shirelang.run.ShireConfiguration abstract class ShireRunner( @@ -10,10 +12,25 @@ abstract class ShireRunner( open val processHandler: ProcessHandler, open val console: ConsoleViewWrapperBase, open val myProject: Project, + open val hole: HobbitHole?, open val prompt: String, ) { abstract fun execute(postFunction: (response: String) -> Unit) fun prepareTask() { } + + fun handleResult() { + when (hole?.interaction) { + InteractionType.AppendCursor -> TODO() + InteractionType.AppendCursorStream -> TODO() + InteractionType.OutputFile -> TODO() + InteractionType.ReplaceSelection -> TODO() + InteractionType.ReplaceCurrentFile -> TODO() + InteractionType.InsertBeforeSelection -> { + TODO() + } + null -> TODO() + } + } } \ No newline at end of file