Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
package com.simiacryptus.skyenet.apps.general
import com.simiacryptus.diff.FileValidationUtils
import com.simiacryptus.diff.addApplyFileDiffLinks
import com.simiacryptus.jopenai.ChatClient
import com.simiacryptus.jopenai.describe.Description
import com.simiacryptus.jopenai.models.OpenAITextModel
import com.simiacryptus.util.JsonUtil
import com.simiacryptus.skyenet.AgentPatterns
import com.simiacryptus.skyenet.Retryable
import com.simiacryptus.skyenet.core.actors.ParsedActor
import com.simiacryptus.skyenet.core.actors.SimpleActor
import com.simiacryptus.skyenet.core.platform.Session
import com.simiacryptus.skyenet.core.platform.User
import com.simiacryptus.skyenet.webui.application.ApplicationInterface
import com.simiacryptus.skyenet.webui.application.ApplicationServer
import com.simiacryptus.skyenet.webui.application.ApplicationSocketManager
import com.simiacryptus.skyenet.webui.session.SessionTask
import com.simiacryptus.skyenet.webui.session.SocketManager
import com.simiacryptus.skyenet.util.MarkdownUtil
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
abstract class PatchApp(
override val root: File,
val session: Session,
val settings: Settings,
val api: ChatClient,
val model: OpenAITextModel,
val promptPrefix: String = """The following command was run and produced an error:"""
) : ApplicationServer(
applicationName = "Magic Code Fixer",
path = "/fixCmd",
showMenubar = false,
) {
companion object {
private val log = LoggerFactory.getLogger(PatchApp::class.java)
const val tripleTilde = "`" + "``" // This is a workaround for the markdown parser when editing this file
}
data class OutputResult(val exitCode: Int, val output: String)
abstract fun codeFiles(): Set
abstract fun codeSummary(paths: List): String
abstract fun output(task: SessionTask): OutputResult
abstract fun searchFiles(searchStrings: List): Set
override val singleInput = true
override val stickyInput = false
override fun newSession(user: User?, session: Session ): SocketManager {
val socketManager = super.newSession(user, session)
val ui = (socketManager as ApplicationSocketManager).applicationInterface
val task = ui.newTask()
Retryable(
ui = ui,
task = task,
process = { content ->
val newTask = ui.newTask(false)
newTask.add("Running Command")
Thread {
run(ui, newTask)
}.start()
newTask.placeholder
}
)
return socketManager
}
abstract fun projectSummary(): String
private fun prunePaths(paths: List, maxSize: Int): List {
val sortedPaths = paths.sortedByDescending { it.toFile().length() }
var totalSize = 0
val prunedPaths = mutableListOf()
for (path in sortedPaths) {
val fileSize = path.toFile().length().toInt()
if (totalSize + fileSize > maxSize) break
prunedPaths.add(path)
totalSize += fileSize
}
return prunedPaths
}
data class ParsedErrors(
val errors: List? = null
)
data class ParsedError(
@Description("The error message")
val message: String? = null,
@Description("Files identified as needing modification and issue-related files")
val relatedFiles: List? = null,
@Description("Files identified as needing modification and issue-related files")
val fixFiles: List? = null,
@Description("Search strings to find relevant files")
val searchStrings: List? = null
)
data class Settings(
var executable: File,
var arguments: String = "",
var workingDirectory: File? = null,
var exitCodeOption: String = "nonzero",
var additionalInstructions: String = "",
val autoFix: Boolean,
)
fun run(
ui: ApplicationInterface,
task: SessionTask,
): OutputResult {
val output = output(task)
if (output.exitCode == 0 && settings.exitCodeOption == "nonzero") {
task.complete(
"""
|