Skip to content

Commit

Permalink
feat(runner): refactor ShireRunner to improve terminal task execution…
Browse files Browse the repository at this point in the history
… and error handling
  • Loading branch information
phodal committed Jul 4, 2024
1 parent df890cb commit b236ad2
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -32,24 +32,26 @@ class ShireProgramRunner : GenericProgramRunner<RunnerSettings>(), Disposable {

val result = AtomicReference<RunContentDescriptor>()

if(!isSubscribed) {
if (!isSubscribed) {
connection.subscribe(ShireRunListener.TOPIC, object : ShireRunListener {
override fun runFinish(string: String, event: ProcessEvent, scriptPath: String) {
val consoleView = (environment.state as? ShireRunConfigurationProfileState)?.console
environment.project.getService(ShireProcessProcessor::class.java)
.process(string, event, scriptPath, consoleView)

ApplicationManager.getApplication().invokeAndWait {
val showRunContent = showRunContent(
shireState.execute(environment.executor, this@ShireProgramRunner),
environment
)
result.set(showRunContent)
}
}
})

isSubscribed = true
}

ApplicationManager.getApplication().invokeAndWait {
val showRunContent = showRunContent(shireState.execute(environment.executor, this), environment)
result.set(showRunContent)
}

return result.get()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ class ShireRunner(

if (runnerContext.hole?.actionLocation == ShireActionLocation.TERMINAL_MENU) {
executeTerminalTask(runnerContext) { response, textRange ->
executePostFunction(runnerContext, runnerContext.hole, null, null)
executePostFunction(runnerContext, runnerContext.hole, response, textRange)
}
} else {
executeLlmTask(runnerContext)
Expand All @@ -65,6 +65,12 @@ class ShireRunner(
private fun executeTerminalTask(context: ShireRunnerContext, postFunction: PostFunction) {
CoroutineScope(Dispatchers.Main).launch {
val handler = terminalLocationExecutor?.bundler(project, userInput)
if (handler == null) {
console.print("Terminal not found", ConsoleViewContentType.ERROR_OUTPUT)
processHandler.destroyProcess()
return@launch
}

val llmResult = StringBuilder()
runBlocking {
LlmProvider.provider(project)?.stream(context.finalPrompt, "", false)?.collect {
Expand Down

0 comments on commit b236ad2

Please sign in to comment.