From d30156f174de728338f0f397b80b4ac4e7241599 Mon Sep 17 00:00:00 2001 From: Andrew Charneski Date: Mon, 2 Sep 2024 12:22:36 -0400 Subject: [PATCH] 1.0.90 (#96) * 1.0.90 * new tasks, refactors * foreach --- .../skyenet/apps/plan/ForeachTask.kt | 51 +++++++++++++++++++ .../skyenet/apps/plan/PlanTask.kt | 4 +- .../skyenet/apps/plan/Settings.kt | 6 +++ .../skyenet/apps/plan/TaskType.kt | 1 + 4 files changed, 61 insertions(+), 1 deletion(-) create mode 100644 webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/ForeachTask.kt diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/ForeachTask.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/ForeachTask.kt new file mode 100644 index 00000000..75312fcf --- /dev/null +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/ForeachTask.kt @@ -0,0 +1,51 @@ +package com.simiacryptus.skyenet.apps.plan + +import com.simiacryptus.skyenet.TabbedDisplay +import com.simiacryptus.skyenet.core.actors.ParsedResponse +import com.simiacryptus.skyenet.webui.session.SessionTask +import org.slf4j.LoggerFactory + +class ForeachTask( + settings: Settings, + planTask: PlanTask +) : AbstractTask(settings, planTask) { + + override fun promptSegment(): String { + return """ +ForeachTask - Execute a task for each item in a list + ** Specify the list of items to iterate over + ** Define the task to be executed for each item + """.trimIndent() + } + + override fun run( + agent: PlanCoordinator, + taskId: String, + userMessage: String, + plan: ParsedResponse, + genState: PlanCoordinator.GenState, + task: SessionTask, + taskTabs: TabbedDisplay + ) { + val items = planTask.foreachItems ?: throw RuntimeException("No items specified for ForeachTask") + items.forEachIndexed { index, item -> + val subTask = agent.ui.newTask(false) + task.add(subTask.placeholder) + + // Create a new PlanTask for each item, copying the original task's properties + val itemTask = planTask.copy( + description = "${planTask.description} - Item $index: $item", + foreachItems = null // Remove the foreach items to prevent infinite recursion + ) + + // Execute the task for this item + val subTaskImpl = settings.getImpl(itemTask) + subTaskImpl.run(agent, "$taskId-$index", userMessage, plan, genState, subTask, taskTabs) + } + task.complete("Completed ForeachTask for ${items.size} items") + } + + companion object { + private val log = LoggerFactory.getLogger(ForeachTask::class.java) + } +} \ No newline at end of file diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/PlanTask.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/PlanTask.kt index 6f92d87d..45cea499 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/PlanTask.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/PlanTask.kt @@ -12,5 +12,7 @@ data class PlanTask( @Description("Command and arguments (in list form) for the task") val command: List? = null, @Description("Working directory for the command execution") - val workingDir: String? = null + val workingDir: String? = null, + @Description("List of items to iterate over") + val foreachItems: List? = null ) \ No newline at end of file diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/Settings.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/Settings.kt index a96591a7..a6efb9f2 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/Settings.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/Settings.kt @@ -21,6 +21,7 @@ data class Settings( val securityAuditEnabled: Boolean = true, val performanceAnalysisEnabled: Boolean = true, val refactorTaskEnabled: Boolean = true, + val foreachTaskEnabled: Boolean = true, val autoFix: Boolean = false, val enableCommandAutoFix: Boolean = false, var commandAutoFixCommands: List = listOf(), @@ -53,6 +54,10 @@ data class Settings( this, planTask ) else throw DisabledTaskException(planTask.taskType) + TaskType.ForeachTask -> if (foreachTaskEnabled) ForeachTask( + this, + planTask + ) else throw DisabledTaskException(planTask.taskType) else -> throw RuntimeException("Unknown task type: ${planTask.taskType}") } } @@ -90,6 +95,7 @@ data class Settings( TaskType.SecurityAudit -> this.securityAuditEnabled TaskType.PerformanceAnalysis -> this.performanceAnalysisEnabled TaskType.RefactorTask -> this.refactorTaskEnabled + TaskType.ForeachTask -> this.foreachTaskEnabled } }.map { this.getImpl(PlanTask(taskType = it)) } } diff --git a/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/TaskType.kt b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/TaskType.kt index 09f6186b..88acf6c1 100644 --- a/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/TaskType.kt +++ b/webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/TaskType.kt @@ -13,4 +13,5 @@ enum class TaskType { SecurityAudit, PerformanceAnalysis, RefactorTask, + ForeachTask, } \ No newline at end of file