Skip to content

Commit

Permalink
1.0.81 (#86)
Browse files Browse the repository at this point in the history
* 1.0.81

* wip

* wip

* Update AddApplyFileDiffLinks.kt

* Update AddApplyFileDiffLinks.kt

* Update AddApplyFileDiffLinks.kt
  • Loading branch information
acharneski authored Jul 2, 2024
1 parent 9244339 commit aee88c0
Show file tree
Hide file tree
Showing 12 changed files with 472 additions and 223 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -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
4 changes: 4 additions & 0 deletions webui/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -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")

Expand Down
51 changes: 37 additions & 14 deletions webui/src/main/kotlin/com/simiacryptus/diff/AddApplyDiffLinks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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)(?<![^\n])```diff\n(.*?)\n```""".toRegex()
val matches = diffPattern.findAll(response).distinct()
val withLinks = matches.fold(response) { markdown, diffBlock ->
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("""<div class="cmd-button">Diff Applied</div>""")
applydiffTask.complete()
buttons.complete()
reverseHrefLink?.clear()
} catch (e: Throwable) {
hrefLink.append("""<div class="cmd-button">Error: ${e.message}</div>""")
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("""<div class="cmd-button">Diff Applied (Bottom to Top)</div>""")
applydiffTask.complete()
buttons.complete()
hrefLink.clear()
} catch (e: Throwable) {
task.error(ui, e)
Expand All @@ -73,15 +96,15 @@ 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(
"Diff" to renderMarkdown("```diff\n$diffVal\n```", ui = ui, tabs = true),
"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)
}
Expand Down
Loading

0 comments on commit aee88c0

Please sign in to comment.