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.
""".trimMargin()
)
fixAll(settings, output, task, ui, api)
} catch (e: Exception) {
task.error(ui, e)
}
return output
}
private fun fixAll(
settings: Settings,
output: OutputResult,
task: SessionTask,
ui: ApplicationInterface,
api: OpenAIClient,
) {
Retryable(ui, task) { content ->
fixAllInternal(
settings = settings,
output = output,
task = task,
ui = ui,
changed = mutableSetOf(),
api = api
)
content.clear()
""
}
}
private fun fixAllInternal(
settings: Settings,
output: OutputResult,
task: SessionTask,
ui: ApplicationInterface,
changed: MutableSet,
api: OpenAIClient,
) {
val plan = ParsedActor(
resultClass = ParsedErrors::class.java,
prompt = """
|You are a helpful AI that helps people with coding.
|
|You will be answering questions about the following project:
|
|Project Root: ${settings.workingDirectory?.absolutePath ?: ""}
|
|Files:
|${projectSummary()}
|
|Given the response of a build/test process, identify one or more distinct errors.
|For each error:
| 1) predict the files that need to be fixed
| 2) predict related files that may be needed to debug the issue
| 3) specify a search string to find relevant files - be as specific as possible
|${if (settings.additionalInstructions.isNotBlank()) "Additional Instructions:\n ${settings.additionalInstructions}\n" else ""}
""".trimMargin(),
model = model
).answer(
listOf(
"""
|The following command was run and produced an error:
|
|${tripleTilde}
|${output.output}
|${tripleTilde}
""".trimMargin()
), api = api
)
task.add(
AgentPatterns.displayMapInTabs(
mapOf(
"Text" to MarkdownUtil.renderMarkdown(plan.text, ui = ui),
"JSON" to MarkdownUtil.renderMarkdown(
"${tripleTilde}json\n${JsonUtil.toJson(plan.obj)}\n${tripleTilde}",
ui = ui
),
)
)
)
val progressHeader = task.header("Processing tasks")
plan.obj.errors?.forEach { error ->
task.header("Processing error: ${error.message}")
task.verbose(MarkdownUtil.renderMarkdown("```json\n${JsonUtil.toJson(error)}\n```", tabs = false, ui = ui))
// Search for files using the provided search strings
val searchResults = error.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() ?: emptySet()
task.verbose(
MarkdownUtil.renderMarkdown(
"""
|Search results:
|
|${searchResults.joinToString("\n") { "* `$it`" }}
""".trimMargin(), tabs = false, ui = ui
)
)
Retryable(ui, task) { content ->
fix(
error, searchResults.toList().map { it.toFile().absolutePath },
output, ui, content, settings.autoFix, changed, api
)
content.toString()
}
}
progressHeader?.clear()
task.append("", false)
}
private fun fix(
error: ParsedError,
additionalFiles: List? = null,
output: OutputResult,
ui: ApplicationInterface,
content: StringBuilder,
autoFix: Boolean,
changed: MutableSet,
api: OpenAIClient,
) {
val paths =
(
(error.fixFiles ?: emptyList()) +
(error.relatedFiles ?: emptyList()) +
(additionalFiles ?: emptyList())
).map {
try {
File(it).toPath()
} catch (e: Throwable) {
log.warn("Error: root=${root} ", e)
null
}
}.filterNotNull()
val prunedPaths = prunePaths(paths, 50 * 1024)
val summary = codeSummary(prunedPaths)
val response = SimpleActor(
prompt = """
|You are a helpful AI that helps people with coding.
|
|You will be answering questions about the following code:
|
|$summary
|
|
|Response should use one or more code patches in diff format within ${tripleTilde}diff code blocks.
|Each diff should be preceded by a header that identifies the file being modified.
|The diff format should use + for line additions, - for line deletions.
|The diff should include 2 lines of context before and after every change.
|
|Example:
|
|Here are the patches:
|
|### src/utils/exampleUtils.js
|${tripleTilde}diff
| // Utility functions for example feature
| const b = 2;
| function exampleFunction() {
|- return b + 1;
|+ return b + 2;
| }
|${tripleTilde}
|
|### tests/exampleUtils.test.js
|${tripleTilde}diff
| // Unit tests for exampleUtils
| const assert = require('assert');
| const { exampleFunction } = require('../src/utils/exampleUtils');
|
| describe('exampleFunction', () => {
|- it('should return 3', () => {
|+ it('should return 4', () => {
| assert.equal(exampleFunction(), 3);
| });
| });
|${tripleTilde}
|
|If needed, new files can be created by using code blocks labeled with the filename in the same manner.
""".trimMargin(),
model = model
).answer(
listOf(
"""
|The following command was run and produced an error:
|
|${tripleTilde}
|${output.output}
|${tripleTilde}
|
|Focus on and Fix the Error:
| ${error.message?.replace("\n", "\n ") ?: ""}
|${if (settings.additionalInstructions.isNotBlank()) "Additional Instructions:\n ${settings.additionalInstructions}\n" else ""}
""".trimMargin()
), api = api
)
var markdown = ui.socketManager?.addApplyFileDiffLinks(
root = root.toPath(),
response = response,
ui = ui,
api = api,
shouldAutoApply = { path ->
if (autoFix && !changed.contains(path)) {
changed.add(path)
true
} else {
false
}
}
)
content.clear()
content.append("