Skip to content

Commit d4b73d9

Browse files
authored
1.3.6 (#142)
* 1.3.6 * Update AutoDevAction.kt
1 parent 3661163 commit d4b73d9

File tree

8 files changed

+146
-91
lines changed

8 files changed

+146
-91
lines changed

build.gradle.kts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ repositories {
2626
val kotlin_version = "1.9.21"
2727
val jetty_version = "11.0.18"
2828
val slf4j_version = "2.0.9"
29-
val skyenet_version = "1.0.56"
29+
val skyenet_version = "1.0.57"
3030
val remoterobot_version = "0.11.21"
3131
dependencies {
3232

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
pluginName=intellij-aicoder
22
pluginRepositoryUrl=https://github.com/SimiaCryptus/intellij-aicoder
3-
pluginVersion=1.3.5
3+
pluginVersion=1.3.6
44

55
jvmArgs=-Xmx8g
66
org.gradle.jvmargs=-Xmx8g

src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/AnalogueFileAction.kt

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -165,15 +165,5 @@ class AnalogueFileAction : FileContextAction<AnalogueFileAction.Settings>() {
165165
scheduledPool.schedule(function, 100, TimeUnit.MILLISECONDS)
166166
}
167167

168-
fun getModuleRootForFile(file: File): File {
169-
var current = file
170-
while (current.parentFile != null) {
171-
if (current.resolve(".git").exists()) {
172-
return current
173-
}
174-
current = current.parentFile
175-
}
176-
return file
177-
}
178168
}
179169
}

src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/AutoDevAction.kt

Lines changed: 25 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -139,6 +139,7 @@ class AutoDevAction : BaseAction() {
139139

140140
### scripts/filename.js
141141
```diff
142+
import com.simiacryptus.skyenet.webui.components.CheckboxTab
142143
- const b = 2;
143144
+ const a = 1;
144145
```
@@ -150,7 +151,8 @@ class AutoDevAction : BaseAction() {
150151
),
151152
val event: AnActionEvent,
152153
) : ActorSystem<AutoDevAgent.ActorTypes>(
153-
actorMap.map { it.key.name to it.value }.toMap(), dataStorage, user, session) {
154+
actorMap.map { it.key.name to it.value }.toMap(), dataStorage, user, session
155+
) {
154156
enum class ActorTypes {
155157
DesignActor,
156158
TaskCodingActor,
@@ -183,17 +185,19 @@ class AutoDevAction : BaseAction() {
183185
userMessage = userMessage,
184186
initialResponse = { it: String -> designActor.answer(toInput(it), api = api) },
185187
outputFn = { design: ParsedResponse<TaskList> ->
186-
// renderMarkdown("${design.text}\n\n```json\n${JsonUtil.toJson(design.obj).indent(" ")}\n```")
187-
AgentPatterns.displayMapInTabs(mapOf(
188-
"Text" to renderMarkdown(design.text),
189-
"JSON" to renderMarkdown("```json\n${toJson(design.obj).indent(" ")}\n```"),
190-
)
191-
)
192-
},
188+
// renderMarkdown("${design.text}\n\n```json\n${JsonUtil.toJson(design.obj).indent(" ")}\n```")
189+
AgentPatterns.displayMapInTabs(
190+
mapOf(
191+
"Text" to renderMarkdown(design.text),
192+
"JSON" to renderMarkdown("```json\n${toJson(design.obj).indent(" ")}\n```"),
193+
)
194+
)
195+
},
193196
ui = ui,
194197
reviseResponse = { userMessages: List<Pair<String, Role>> ->
195198
designActor.respond(
196-
messages = (userMessages.map { ApiModel.ChatMessage(it.second, it.first.toContentList()) }.toTypedArray<ApiModel.ChatMessage>()),
199+
messages = (userMessages.map { ApiModel.ChatMessage(it.second, it.first.toContentList()) }
200+
.toTypedArray<ApiModel.ChatMessage>()),
197201
input = toInput(userMessage),
198202
api = api
199203
)
@@ -205,7 +209,7 @@ class AutoDevAction : BaseAction() {
205209

206210
try {
207211
architectureResponse.obj.tasks.forEach { (paths, description) ->
208-
task.complete(ui.hrefLink(renderMarkdown("Task: $description")){
212+
task.complete(ui.hrefLink(renderMarkdown("Task: $description")) {
209213
val task = ui.newTask()
210214
task.header("Task: $description")
211215
val process = { it: StringBuilder ->
@@ -226,12 +230,15 @@ class AutoDevAction : BaseAction() {
226230
""".trimMargin()
227231
}
228232
ui.socketManager.addApplyDiffLinks2(
233+
root = root,
229234
code = codeFiles,
230235
response = taskActor.answer(listOf(
231236
codeSummary(),
232237
userMessage,
233238
filter.entries.joinToString("\n\n") {
234-
"# ${it.key}\n```${it.key.split('.').last()?.let { escapeHtml4(it).indent(" ") }}\n${it.value.indent(" ")}\n```"
239+
"# ${it.key}\n```${
240+
it.key.split('.').last()?.let { escapeHtml4(it).indent(" ") }
241+
}\n${it.value.indent(" ")}\n```"
235242
},
236243
architectureResponse.text,
237244
"Provide a change for ${paths?.joinToString(",") { it } ?: ""} ($description)"
@@ -266,6 +273,8 @@ class AutoDevAction : BaseAction() {
266273
}
267274
}
268275

276+
val taskStates = mutableMapOf<String, TaskState>()
277+
269278
companion object {
270279
private val log = LoggerFactory.getLogger(AutoDevAction::class.java)
271280
private val agents = mutableMapOf<Session, AutoDevApp>()
@@ -306,4 +315,9 @@ class AutoDevAction : BaseAction() {
306315
}
307316

308317
}
318+
enum class TaskState {
319+
Pending,
320+
InProgress,
321+
Completed
322+
}
309323
}

src/main/kotlin/com/github/simiacryptus/aicoder/actions/generic/MultiDiffChatAction.kt

Lines changed: 26 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,26 +6,26 @@ import com.github.simiacryptus.aicoder.actions.dev.AppServer
66
import com.github.simiacryptus.aicoder.config.AppSettingsState
77
import com.github.simiacryptus.aicoder.config.AppSettingsState.Companion.chatModel
88
import com.github.simiacryptus.aicoder.util.ComputerLanguage
9+
import com.github.simiacryptus.aicoder.util.UITools
910
import com.github.simiacryptus.aicoder.util.addApplyDiffLinks2
1011
import com.intellij.openapi.actionSystem.AnActionEvent
1112
import com.intellij.openapi.actionSystem.PlatformDataKeys
1213
import com.intellij.openapi.command.WriteCommandAction
1314
import com.intellij.openapi.fileEditor.FileDocumentManager
14-
import com.simiacryptus.skyenet.core.actors.CodingActor.Companion.indent
1515
import com.simiacryptus.skyenet.core.platform.ApplicationServices
1616
import com.simiacryptus.skyenet.core.platform.Session
1717
import com.simiacryptus.skyenet.core.platform.StorageInterface
1818
import com.simiacryptus.skyenet.core.platform.User
19+
import com.simiacryptus.skyenet.webui.application.ApplicationInterface
1920
import com.simiacryptus.skyenet.webui.application.ApplicationServer
2021
import com.simiacryptus.skyenet.webui.chat.ChatServer
2122
import com.simiacryptus.skyenet.webui.chat.ChatSocketManager
2223
import com.simiacryptus.skyenet.webui.session.SessionTask
2324
import com.simiacryptus.skyenet.webui.session.SocketManager
24-
import org.apache.commons.text.StringEscapeUtils.escapeHtml4
25+
import com.simiacryptus.skyenet.webui.util.MarkdownUtil.renderMarkdown
2526
import org.slf4j.LoggerFactory
2627
import java.awt.Desktop
2728
import java.io.File
28-
import java.nio.file.Path
2929

3030
class MultiDiffChatAction : BaseAction() {
3131

@@ -39,10 +39,18 @@ class MultiDiffChatAction : BaseAction() {
3939
virtualFiles?.associate { it to ComputerLanguage.findByExtension(it.extension ?: "")?.name } ?: mapOf()
4040
val virtualFileMap = virtualFiles?.associate { it.toNioPath() to it } ?: mapOf()
4141
val codeFiles = mutableMapOf<String, String>()
42-
val root = virtualFiles?.map { file ->
43-
file.toNioPath()
44-
}?.toTypedArray()?.commonRoot()!!
45-
val paths = virtualFiles.associate { file ->
42+
val folder = UITools.getSelectedFolder(e)
43+
val root = if (null != folder) {
44+
folder.toFile.toPath()
45+
} else {
46+
getModuleRootForFile(UITools.getSelectedFile(e)?.parent?.toFile ?: throw RuntimeException("")).toPath()
47+
}
48+
49+
// val root = virtualFiles?.map { file ->
50+
// file.toNioPath()
51+
// }?.toTypedArray()?.commonRoot()!!
52+
53+
virtualFiles?.associate { file ->
4654
val relative = root.relativize(file.toNioPath())
4755
val path = relative.toString()
4856
val language = languages[file] ?: "plaintext"
@@ -53,26 +61,27 @@ class MultiDiffChatAction : BaseAction() {
5361

5462
fun codeSummary() = codeFiles.entries.joinToString("\n\n") { (path, code) ->
5563
"# $path\n```${
56-
path.split('.').lastOrNull()?.let { escapeHtml4(it).indent(" ") }
57-
}\n${code?.let { escapeHtml4(it).indent(" ") }}\n```"
64+
path.split('.').lastOrNull()?.let { /*escapeHtml4*/(it)/*.indent(" ")*/ }
65+
}\n${code?.let { /*escapeHtml4*/(it)/*.indent(" ")*/ }}\n```"
5866
}
5967
val session = StorageInterface.newGlobalID()
6068
//DataStorage.sessionPaths[session] = root.toFile()
6169

70+
val codeSummary = codeSummary()
6271
agents[session] = object : ChatSocketManager(
6372
session = session,
6473
model = AppSettingsState.instance.smartModel.chatModel(),
6574
userInterfacePrompt = """
6675
|
67-
|${escapeHtml4(codeSummary())}
76+
|$codeSummary
6877
|
6978
""".trimMargin().trim(),
7079
systemPrompt = """
7180
You are a helpful AI that helps people with coding.
7281
7382
You will be answering questions about the following code:
7483
75-
${codeSummary()}
84+
$codeSummary
7685
7786
Response should use one or more code patches in diff format within ```diff code blocks.
7887
Each diff should be preceded by a header that identifies the file being modified.
@@ -97,7 +106,10 @@ class MultiDiffChatAction : BaseAction() {
97106
) {
98107
override fun renderResponse(response: String, task: SessionTask): String {
99108
val html = addApplyDiffLinks2(
100-
code = codeFiles, response = response, handle = { newCodeMap ->
109+
root = root,
110+
code = codeFiles,
111+
response = response,
112+
handle = { newCodeMap ->
101113
newCodeMap.map { (path, newCode) ->
102114
val prev = codeFiles[path]
103115
if (prev != newCode) {
@@ -117,8 +129,8 @@ class MultiDiffChatAction : BaseAction() {
117129
""
118130
}
119131
}
120-
}, task = task, ui = null,)
121-
return """<div>$html</div>"""
132+
}, task = task, ui = ApplicationInterface(this),)
133+
return """<div>${renderMarkdown(html)}</div>"""
122134
}
123135
}
124136

@@ -155,28 +167,3 @@ class MultiDiffChatAction : BaseAction() {
155167

156168
}
157169
}
158-
159-
fun Array<Path>.commonRoot() : Path = when {
160-
isEmpty() -> error("No paths")
161-
size == 1 && first().toFile().isFile -> first().parent
162-
size == 1 -> first()
163-
else -> this.reduce { a, b ->
164-
when {
165-
a.startsWith(b) -> b
166-
b.startsWith(a) -> a
167-
else -> when (val common = a.commonPrefixWith(b)) {
168-
a -> a
169-
b -> b
170-
else -> common.toAbsolutePath()
171-
}
172-
}
173-
}
174-
}
175-
private fun Path.commonPrefixWith(b: Path): Path {
176-
val a = this
177-
val aParts = a.toAbsolutePath().toString().split(File.separator)
178-
val bParts = b.toAbsolutePath().toString().split(File.separator)
179-
val common = aParts.zip(bParts).takeWhile { (a, b) -> a == b }.map { it.first }
180-
return File(File.separator + common.joinToString(File.separator)).toPath()
181-
}
182-

0 commit comments

Comments
 (0)