Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

1.0.90 #95

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# Gradle Releases -> https://github.com/gradle/gradle/releases
libraryGroup = com.simiacryptus.skyenet
libraryVersion = 1.0.89
libraryVersion = 1.0.90
gradleVersion = 7.6.1
kotlin.daemon.jvmargs=-Xmx2g
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class CmdPatchApp(
session: Session,
settings: Settings,
api: OpenAIClient,
val virtualFiles: Array<out File>?,
val files: Array<out File>?,
model: OpenAITextModel
) : PatchApp(root.toFile(), session, settings, api, model) {
companion object {
Expand Down Expand Up @@ -59,7 +59,7 @@ class CmdPatchApp(
return codeFiles
}

override fun codeFiles() = getFiles(virtualFiles)
override fun codeFiles() = getFiles(files)
.filter { it.toFile().length() < 1024 * 1024 / 2 } // Limit to 0.5MB
.map { root.toPath().relativize(it) ?: it }.toSet()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
package com.simiacryptus.skyenet.apps.general

import com.simiacryptus.diff.FileValidationUtils
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.jopenai.models.OpenAITextModel
import com.simiacryptus.skyenet.core.platform.Session
import com.simiacryptus.skyenet.webui.session.SessionTask
import java.io.File
import java.nio.file.Path

class CommandPatchApp(
root: File,
session: Session,
settings: Settings,
api: OpenAIClient,
model: OpenAITextModel,
private val files: Array<out File>?,
val command: String,
) : PatchApp(root, session, settings, api, model) {
override fun codeFiles() = getFiles(files)
.filter { it.toFile().length() < 1024 * 1024 / 2 } // Limit to 0.5MB
.map { root.toPath().relativize(it) ?: it }.toSet()

override fun codeSummary(paths: List<Path>): String = paths
.filter { it.toFile().exists() }
.joinToString("\n\n") { path ->
"""
|# ${settings.workingDirectory?.toPath()?.relativize(path)}
|$tripleTilde${path.toString().split('.').lastOrNull()}
|${path.toFile().readText(Charsets.UTF_8)}
|$tripleTilde
""".trimMargin()
}

override fun output(task: SessionTask) = OutputResult(
exitCode = 1,
output = command
)

override fun projectSummary(): String {
val codeFiles = codeFiles()
return codeFiles
.asSequence()
.filter { settings.workingDirectory?.toPath()?.resolve(it)?.toFile()?.exists() == true }
.distinct().sorted()
.joinToString("\n") { path ->
"* ${path} - ${
settings.workingDirectory?.toPath()?.resolve(path)?.toFile()?.length() ?: "?"
} bytes".trim()
}
}

override fun searchFiles(searchStrings: List<String>): Set<Path> {
return searchStrings.flatMap { searchString ->
FileValidationUtils.filteredWalk(settings.workingDirectory!!) { !FileValidationUtils.isGitignore(it.toPath()) }
.filter { FileValidationUtils.isLLMIncludable(it) }
.filter { it.readText().contains(searchString, ignoreCase = true) }
.map { it.toPath() }
.toList()
}.toSet()
}

companion object {
fun getFiles(
files: Array<out File>?
): MutableSet<Path> {
val codeFiles = mutableSetOf<Path>() // Set to avoid duplicates
files?.forEach { file ->
if (file.isDirectory) {
if (file.name.startsWith(".")) return@forEach
if (FileValidationUtils.isGitignore(file.toPath())) return@forEach
if (file.name.endsWith(".png")) return@forEach
if (file.length() > 1024 * 256) return@forEach
codeFiles.addAll(getFiles(file.listFiles()))
} else {
codeFiles.add((file.toPath()))
}
}
return codeFiles
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -354,4 +354,7 @@ abstract class PatchApp(
content.append("<div>${MarkdownUtil.renderMarkdown(markdown!!)}</div>")
}

}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.simiacryptus.skyenet.apps.plan

import com.simiacryptus.skyenet.TabbedDisplay
import com.simiacryptus.skyenet.core.actors.ParsedResponse
import com.simiacryptus.skyenet.core.actors.SimpleActor
import com.simiacryptus.skyenet.webui.session.SessionTask
import com.simiacryptus.skyenet.apps.general.PatchApp
import com.simiacryptus.jopenai.OpenAIClient
import com.simiacryptus.skyenet.apps.general.CommandPatchApp
import org.slf4j.LoggerFactory
import java.io.File

abstract class AbstractAnalysisTask(
settings: Settings,
planTask: PlanTask
) : AbstractTask(settings, planTask) {

abstract val actorName: String
abstract val actorPrompt: String

protected val analysisActor by lazy {
SimpleActor(
name = actorName,
prompt = actorPrompt,
model = settings.model,
temperature = settings.temperature,
)
}

override fun run(
agent: PlanCoordinator,
taskId: String,
userMessage: String,
plan: ParsedResponse<PlanCoordinator.TaskBreakdownResult>,
genState: PlanCoordinator.GenState,
task: SessionTask,
taskTabs: TabbedDisplay
) {
val analysisResult = analysisActor.answer(
listOf(
userMessage,
plan.text,
getPriorCode(genState),
getInputFileCode(),
"${getAnalysisInstruction()}:\n${getInputFileCode()}",
).filter { it.isNotBlank() }, api = agent.api
)
genState.taskResult[taskId] = analysisResult
applyChanges(agent, task, analysisResult)
}

abstract fun getAnalysisInstruction(): String

private fun applyChanges(agent: PlanCoordinator, task: SessionTask, analysisResult: String) {
val outputResult = CommandPatchApp(
root = agent.root.toFile(),
session = agent.session,
settings = PatchApp.Settings(
executable = File("dummy"),
workingDirectory = agent.root.toFile(),
exitCodeOption = "nonzero",
additionalInstructions = "",
autoFix = agent.settings.autoFix
),
api = agent.api as OpenAIClient,
model = agent.settings.model,
files = agent.files,
command = analysisResult
).run(
ui = agent.ui,
task = task
)
if (outputResult.exitCode == 0) {
task.add("${actorName} completed and suggestions have been applied successfully.")
} else {
task.add("${actorName} completed, but failed to apply suggestions. Exit code: ${outputResult.exitCode}")
}
}

companion object {
private val log = LoggerFactory.getLogger(AbstractAnalysisTask::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import java.nio.file.Path

abstract class AbstractTask(
val settings: Settings,
val task: PlanCoordinator.Task
val planTask: PlanTask
) {
val outputFiles: List<String>? = task.output_files
val inputFiles: List<String>? = task.input_files
val taskDependencies: List<String>? = task.task_dependencies
val description: String? = task.description
val outputFiles: List<String>? = planTask.output_files
val inputFiles: List<String>? = planTask.input_files
val taskDependencies: List<String>? = planTask.task_dependencies
val description: String? = planTask.description
var state: TaskState? = TaskState.Pending
val codeFiles = mutableMapOf<Path, String>()

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.simiacryptus.skyenet.apps.plan

import org.slf4j.LoggerFactory

class CodeOptimizationTask(
settings: Settings,
planTask: PlanTask
) : AbstractAnalysisTask(settings, planTask) {
override val actorName = "CodeOptimization"
override val actorPrompt = """
Analyze the provided code and suggest optimizations to improve code quality. Focus exclusively on:
1. Code structure and organization
2. Readability improvements
3. Maintainability enhancements
4. Proper use of language-specific features and best practices
5. Design pattern applications
|
|Provide detailed explanations for each suggested optimization, including:
|- The reason for the optimization
|- The expected benefits
|- Any potential trade-offs or considerations
|
Format the response as a markdown document with appropriate headings and code snippets.
Use diff format to show the proposed changes clearly.
""".trimIndent()

override fun promptSegment(): String {
return """
CodeOptimization - Analyze and optimize existing code for better readability, maintainability, and adherence to best practices
** Specify the files to be optimized
** Optionally provide specific areas of focus for the optimization (e.g., code structure, readability, design patterns)
""".trimMargin()
}

override fun getAnalysisInstruction(): String {
return "Optimize the following code for better readability and maintainability"
}

companion object {
private val log = LoggerFactory.getLogger(CodeOptimizationTask::class.java)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.simiacryptus.skyenet.apps.plan

import org.slf4j.LoggerFactory

class CodeReviewTask(
settings: Settings,
planTask: PlanTask
) : AbstractAnalysisTask(settings, planTask) {
override val actorName: String = "CodeReview"
override val actorPrompt: String = """
Perform a comprehensive code review for the provided code files. Analyze the code for:
1. Code quality and readability
2. Potential bugs or errors
|3. Performance issues
|4. Security vulnerabilities
|5. Adherence to best practices and coding standards
|6. Suggestions for improvements or optimizations
|
Provide a detailed review with specific examples and recommendations for each issue found.
Format the response as a markdown document with appropriate headings and code snippets.
""".trimIndent()

override fun getAnalysisInstruction(): String = "Review the following code"

override fun promptSegment(): String {
return """
|CodeReview - Perform an automated code review and provide suggestions for improvements
| ** Specify the files to be reviewed
| ** Optionally provide specific areas of focus for the review
""".trimMargin()
}


companion object {
private val log = LoggerFactory.getLogger(CodeReviewTask::class.java)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ import java.util.concurrent.Semaphore

class CommandAutoFixTask(
settings: Settings,
task: PlanCoordinator.Task
) : AbstractTask(settings, task) {
planTask: PlanTask
) : AbstractTask(settings, planTask) {
override fun promptSegment(): String {
return """
|CommandAutoFix - Run a command and automatically fix any issues that arise
Expand Down Expand Up @@ -46,7 +46,7 @@ class CommandAutoFixTask(
} else {
Retryable(agent.ui, task = task) {
val task = agent.ui.newTask(false).apply { it.append(placeholder) }
val alias = this.task.command?.first()
val alias = this.planTask.command?.first()
val commandAutoFixCommands = agent.settings.commandAutoFixCommands
val cmds = commandAutoFixCommands.filter {
File(it).name.startsWith(alias ?: "")
Expand All @@ -60,14 +60,14 @@ class CommandAutoFixTask(
session = agent.session,
settings = PatchApp.Settings(
executable = File(executable),
arguments = this.task.command?.drop(1)?.joinToString(" ") ?: "",
arguments = this.planTask.command?.drop(1)?.joinToString(" ") ?: "",
workingDirectory = agent.root.toFile(),
exitCodeOption = "nonzero",
additionalInstructions = "",
autoFix = agent.settings.autoFix
),
api = agent.api as OpenAIClient,
virtualFiles = agent.virtualFiles,
files = agent.files,
model = agent.settings.model,
).run(
ui = agent.ui,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ import java.util.concurrent.Semaphore

class DocumentationTask(
settings: Settings,
task: PlanCoordinator.Task
) : AbstractTask(settings, task) {
planTask: PlanTask
) : AbstractTask(settings, planTask) {
override fun promptSegment(): String {
return """
|Documentation - Generate documentation
Expand Down
Loading
Loading