-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
24 changed files
with
568 additions
and
375 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
82 changes: 82 additions & 0 deletions
82
webui/src/main/kotlin/com/simiacryptus/skyenet/apps/general/CommandPatchApp.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -354,4 +354,7 @@ abstract class PatchApp( | |
content.append("<div>${MarkdownUtil.renderMarkdown(markdown!!)}</div>") | ||
} | ||
|
||
} | ||
} | ||
|
||
|
||
|
83 changes: 83 additions & 0 deletions
83
webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/AbstractAnalysisTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
42 changes: 42 additions & 0 deletions
42
webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/CodeOptimizationTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
37 changes: 37 additions & 0 deletions
37
webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/CodeReviewTask.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.