diff --git a/gradle.properties b/gradle.properties index eb5ccd87..72fd3df2 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,4 +1,4 @@ # Gradle Releases -> https://github.com/gradle/gradle/releases libraryGroup = com.simiacryptus.skyenet -libraryVersion = 1.0.80 +libraryVersion = 1.0.81 gradleVersion = 7.6.1 diff --git a/webui/build.gradle.kts b/webui/build.gradle.kts index 760cb88f..083bb6ff 100644 --- a/webui/build.gradle.kts +++ b/webui/build.gradle.kts @@ -44,6 +44,10 @@ dependencies { compileOnly(group = "software.amazon.awssdk", name = "aws-sdk-java", version = "2.21.9") compileOnly("org.jsoup:jsoup:1.17.2") + + implementation("com.google.zxing:core:3.5.3") + implementation("com.google.zxing:javase:3.5.3") + implementation("org.openapitools:openapi-generator:7.3.0") implementation("org.openapitools:openapi-generator-cli:7.3.0") diff --git a/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyDiffLinks.kt b/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyDiffLinks.kt index c531aeec..7ff76c44 100644 --- a/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyDiffLinks.kt +++ b/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyDiffLinks.kt @@ -14,47 +14,70 @@ fun SocketManagerBase.addApplyDiffLinks( task: SessionTask, ui: ApplicationInterface, ): String { + + + val patch = { code: String, diff: String -> + val isCurlyBalanced = FileValidationUtils.isCurlyBalanced(code) + val isSquareBalanced = FileValidationUtils.isSquareBalanced(code) + val isParenthesisBalanced = FileValidationUtils.isParenthesisBalanced(code) + val isQuoteBalanced = FileValidationUtils.isQuoteBalanced(code) + val isSingleQuoteBalanced = FileValidationUtils.isSingleQuoteBalanced(code) + var newCode = IterativePatchUtil.patch(code, diff) + newCode = newCode.replace("\r", "") + val isCurlyBalancedNew = FileValidationUtils.isCurlyBalanced(newCode) + val isSquareBalancedNew = FileValidationUtils.isSquareBalanced(newCode) + val isParenthesisBalancedNew = FileValidationUtils.isParenthesisBalanced(newCode) + val isQuoteBalancedNew = FileValidationUtils.isQuoteBalanced(newCode) + val isSingleQuoteBalancedNew = FileValidationUtils.isSingleQuoteBalanced(newCode) + val isError = ((isCurlyBalanced && !isCurlyBalancedNew) || + (isSquareBalanced && !isSquareBalancedNew) || + (isParenthesisBalanced && !isParenthesisBalancedNew) || + (isQuoteBalanced && !isQuoteBalancedNew) || + (isSingleQuoteBalanced && !isSingleQuoteBalancedNew)) + PatchResult(newCode, !isError) + } + val diffPattern = """(?s)(? val diffVal: String = diffBlock.groupValues[1] - val applydiffTask = ui.newTask(false) + val buttons = ui.newTask(false) lateinit var hrefLink: StringBuilder var reverseHrefLink: StringBuilder? = null - hrefLink = applydiffTask.complete(hrefLink("Apply Diff", classname = "href-link cmd-button") { + hrefLink = buttons.complete(hrefLink("Apply Diff", classname = "href-link cmd-button") { try { - val newCode = IterativePatchUtil.patch(code(), diffVal).replace("\r", "") - handle(newCode) + val newCode = patch(code(), diffVal) + handle(newCode.newCode) hrefLink.set("""
""") - applydiffTask.complete() + buttons.complete() reverseHrefLink?.clear() } catch (e: Throwable) { hrefLink.append(""" """) - applydiffTask.complete() + buttons.complete() task.error(ui, e) } })!! - val patch = IterativePatchUtil.patch(code(), diffVal).replace("\r", "") + val patch = patch(code(), diffVal).newCode val test1 = DiffUtil.formatDiff( DiffUtil.generateDiff( code().replace("\r", "").lines(), patch.lines() ) ) - val patchRev = IterativePatchUtil.patch( + val patchRev = patch( code().lines().reversed().joinToString("\n"), diffVal.lines().reversed().joinToString("\n") - ).replace("\r", "") + ).newCode if (patchRev != patch) { - reverseHrefLink = applydiffTask.complete(hrefLink("(Bottom to Top)", classname = "href-link cmd-button") { + reverseHrefLink = buttons.complete(hrefLink("(Bottom to Top)", classname = "href-link cmd-button") { try { val reversedCode = code().lines().reversed().joinToString("\n") val reversedDiff = diffVal.lines().reversed().joinToString("\n") - val newReversedCode = IterativePatchUtil.patch(reversedCode, reversedDiff).replace("\r", "") + val newReversedCode = patch(reversedCode, reversedDiff).newCode val newCode = newReversedCode.lines().reversed().joinToString("\n") handle(newCode) reverseHrefLink!!.set(""" """) - applydiffTask.complete() + buttons.complete() hrefLink.clear() } catch (e: Throwable) { task.error(ui, e) @@ -73,7 +96,7 @@ fun SocketManagerBase.addApplyDiffLinks( "Diff" to renderMarkdown("```diff\n$diffVal\n```", ui = ui, tabs = true), "Verify" to renderMarkdown("```diff\n$test1\n```", ui = ui, tabs = true), ), ui = ui, split = true - ) + "\n" + applydiffTask.placeholder + ) + "\n" + buttons.placeholder } else { displayMapInTabs( mapOf( @@ -81,7 +104,7 @@ fun SocketManagerBase.addApplyDiffLinks( "Verify" to renderMarkdown("```diff\n$test1\n```", ui = ui, tabs = true), "Reverse" to renderMarkdown("```diff\n$test2\n```", ui = ui, tabs = true), ), ui = ui, split = true - ) + "\n" + applydiffTask.placeholder + ) + "\n" + buttons.placeholder } markdown.replace(diffBlock.value, newValue) } diff --git a/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyFileDiffLinks.kt b/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyFileDiffLinks.kt index 2cda1f5e..4d55217f 100644 --- a/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyFileDiffLinks.kt +++ b/webui/src/main/kotlin/com/simiacryptus/diff/AddApplyFileDiffLinks.kt @@ -1,34 +1,63 @@ package com.simiacryptus.diff -import com.simiacryptus.diff.IterativePatchUtil.patch +import com.simiacryptus.jopenai.API +import com.simiacryptus.jopenai.OpenAIClient +import com.simiacryptus.jopenai.models.ChatModels import com.simiacryptus.skyenet.AgentPatterns +import com.simiacryptus.skyenet.AgentPatterns.displayMapInTabs +import com.simiacryptus.skyenet.core.actors.SimpleActor import com.simiacryptus.skyenet.set import com.simiacryptus.skyenet.webui.application.ApplicationInterface -import com.simiacryptus.skyenet.webui.session.SessionTask import com.simiacryptus.skyenet.webui.session.SocketManagerBase -import com.simiacryptus.skyenet.webui.util.MarkdownUtil import com.simiacryptus.skyenet.webui.util.MarkdownUtil.renderMarkdown +import org.apache.commons.codec.digest.Md5Crypt import java.io.File +import java.nio.file.Files import java.nio.file.Path import java.util.concurrent.TimeUnit +import java.util.regex.Pattern import kotlin.io.path.readText +private fun String.reverseLines(): String = lines().reversed().joinToString("\n") + fun SocketManagerBase.addApplyFileDiffLinks( root: Path, - code: () -> Map