Skip to content

Commit fe494cd

Browse files
committed
wip
1 parent d363188 commit fe494cd

File tree

2 files changed

+17
-18
lines changed

2 files changed

+17
-18
lines changed

webui/src/main/kotlin/com/simiacryptus/diff/AddApplyFileDiffLinks.kt

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -210,35 +210,33 @@ open class AddApplyFileDiffLinks {
210210
)
211211
}
212212
val headerPattern = """(?<![^\n])#+\s*([^\n]+)""".toRegex() // capture filename
213-
val codeblockPattern = """(?s)(?<![^\n])```([^\n]*)(\n.*?\n)```""".toRegex() // capture filename
213+
val codeblockPattern = """(?s)(?<![^\n])```([^\n]*)\n(.*?)\n```""".toRegex() // capture filename
214+
val codeblockGreedyPattern = """(?s)(?<![^\n])```([^\n]*)\n(.*)\n```""".toRegex() // capture filename
214215
val headers = headerPattern.findAll(response).map { it.range to it.groupValues[1] }.toList()
215-
val findAll = codeblockPattern.findAll(response).toList()
216-
val codeblocks = findAll.filter { block ->
216+
val findAll = codeblockPattern.findAll(response).toList().groupBy { block -> headers.lastOrNull { it.first.last <= block.range.first }?.second ?: defaultFile }
217+
val findAllGreedy = codeblockGreedyPattern.findAll(response).toList().groupBy { block -> headers.lastOrNull { it.first.last <= block.range.first }?.second ?: defaultFile }
218+
val resolvedMatches = mutableMapOf<String?,List<MatchResult>>()
219+
if (findAllGreedy.values.flatten().any { it.groupValues[1] == "markdown" }) {
220+
resolvedMatches.putAll(findAllGreedy)
221+
} else {
222+
resolvedMatches.putAll(findAll)
223+
}
224+
val codeblocks = resolvedMatches.filter { (header, block) ->
217225
try {
218-
val header = headers.lastOrNull { it.first.last <= block.range.first }?.second ?: defaultFile
219-
if (header == null) {
220-
return@filter false
221-
}
222-
val filename = resolve(root, header)
223-
!root.resolve(filename).toFile().exists()
226+
!root.resolve(resolve(root, header ?: return@filter false)).toFile().exists()
224227
} catch (e: Throwable) {
225228
log.info("Error processing code block", e)
226229
false
227230
}
228-
}.map { it.range to it }.toList()
229-
val patchBlocks = findAll.filter { block ->
231+
}.flatMap { it.value }.map { it.range to it }.toList()
232+
val patchBlocks = resolvedMatches.filter { (header, block) ->
230233
try {
231-
val header = headers.lastOrNull { it.first.last <= block.range.first }?.second ?: defaultFile
232-
if (header == null) {
233-
return@filter false
234-
}
235-
val filename = resolve(root, header)
236-
root.resolve(filename).toFile().exists()
234+
root.resolve(resolve(root, header ?: return@filter false)).toFile().exists()
237235
} catch (e: Throwable) {
238236
log.info("Error processing code block", e)
239237
false
240238
}
241-
}.map { it.range to it }.toList()
239+
}.flatMap { it.value }.map { it.range to it }.toList()
242240

243241
// Process diff blocks and add patch links
244242
val withPatchLinks: String = patchBlocks.foldIndexed(response) { index, markdown, diffBlock ->

webui/src/main/kotlin/com/simiacryptus/skyenet/apps/plan/tools/file/DocumentationTask.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ class DocumentationTask(
107107
api = api,
108108
shouldAutoApply = { agent.planSettings.autoFix },
109109
model = planSettings.getTaskSettings(TaskType.Documentation).model ?: planSettings.defaultModel,
110+
defaultFile = taskConfig?.output_files?.firstOrNull(),
110111
)
111112
task.complete()
112113
onComplete()

0 commit comments

Comments
 (0)