Skip to content

Commit

Permalink
1.0.90 (#96)
Browse files Browse the repository at this point in the history
* 1.0.90

* new tasks, refactors

* foreach
  • Loading branch information
acharneski authored Sep 2, 2024
1 parent 0bc0796 commit d30156f
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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<PlanCoordinator.TaskBreakdownResult>,
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)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ data class PlanTask(
@Description("Command and arguments (in list form) for the task")
val command: List<String>? = 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<String>? = null
)
Original file line number Diff line number Diff line change
Expand Up @@ -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<String> = listOf(),
Expand Down Expand Up @@ -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}")
}
}
Expand Down Expand Up @@ -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)) }
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,5 @@ enum class TaskType {
SecurityAudit,
PerformanceAnalysis,
RefactorTask,
ForeachTask,
}

0 comments on commit d30156f

Please sign in to comment.