Skip to content

Commit

Permalink
1.8.6
Browse files Browse the repository at this point in the history
  • Loading branch information
acharneski committed Nov 22, 2024
1 parent 406c2e7 commit bd90adf
Show file tree
Hide file tree
Showing 29 changed files with 149 additions and 78 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.simiacryptus.aicoder

import com.github.simiacryptus.aicoder.actions.generic.SessionProxyServer
import com.github.simiacryptus.aicoder.config.AppSettingsState
import com.github.simiacryptus.aicoder.util.UITools
import com.intellij.openapi.progress.ProgressIndicator
import com.intellij.openapi.project.Project
import com.simiacryptus.skyenet.webui.chat.ChatServer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ open class CustomEditAction : SelectionAction<String>() {
}

override fun processSelection(state: SelectionState, instruction: String?): String {
if (instruction == null || instruction.isBlank()) return state.selectedText ?: ""
if (instruction.isNullOrBlank()) return state.selectedText ?: ""
return try {
UITools.run(state.project, "Processing Edit", true) { progress ->
progress.isIndeterminate = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import com.simiacryptus.skyenet.webui.application.ApplicationServer
import com.simiacryptus.skyenet.webui.chat.ChatSocketManager
import com.simiacryptus.skyenet.webui.session.SessionTask
import org.slf4j.LoggerFactory
import java.text.SimpleDateFormat

class LineFilterChatAction : BaseAction() {
private lateinit var lines: List<String>
Expand Down Expand Up @@ -92,6 +93,7 @@ class LineFilterChatAction : BaseAction() {
append("001\n## Injected subtitle\n\n025\n026\n\n013\n014\n")
append("```")
}.trimMargin()
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
SessionProxyServer.agents[session] = object : ChatSocketManager(
session = session,
model = AppSettingsState.instance.smartModel.chatModel(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import com.simiacryptus.skyenet.core.platform.Session
import com.simiacryptus.skyenet.webui.application.AppInfoData
import com.simiacryptus.skyenet.webui.application.ApplicationServer
import org.slf4j.LoggerFactory
import java.text.SimpleDateFormat

class CodeChatAction : BaseAction() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT
Expand Down Expand Up @@ -43,6 +44,7 @@ class CodeChatAction : BaseAction() {
loadImages = false,
showMenubar = false
)
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")

val server = AppServer.getServer(e.project)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,11 @@ import org.slf4j.LoggerFactory
import java.awt.BorderLayout
import java.io.File
import java.nio.file.Files
import java.text.SimpleDateFormat
import javax.swing.*
import kotlin.collections.set

class CommandAutofixAction : BaseAction() {
private lateinit var event: AnActionEvent

/**
* Returns the thread that should be used for action update.
*/
Expand All @@ -53,19 +52,18 @@ class CommandAutofixAction : BaseAction() {
UITools.showErrorDialog(event.project, "Failed to execute command autofix: ${e.message}", "Error")
}
}
val folder = UITools.getSelectedFolder(event)
val root = if (null != folder) {
folder.toFile.toPath()
} else {
event.project?.basePath?.let { File(it).toPath() }
}!!

/**
* Sets up and launches the patch app session
*/
private fun setupAndLaunchSession(event: AnActionEvent, settings: PatchApp.Settings, virtualFiles: Array<VirtualFile>?) {
val project = event.project ?: return

val folder = UITools.getSelectedFolder(event)
val root = if (null != folder) {
folder.toFile.toPath()
} else {
event.project?.basePath?.let { File(it).toPath() }
}!!
val session = Session.newGlobalID()
val patchApp = CmdPatchApp(
root,
Expand All @@ -83,6 +81,7 @@ class CommandAutofixAction : BaseAction() {
loadImages = false,
showMenubar = false
)
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
val server = AppServer.getServer(event.project)
Thread {
Thread.sleep(500)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import java.io.ByteArrayOutputStream
import java.io.File
import java.io.IOException
import java.nio.file.Path
import java.text.SimpleDateFormat
import java.util.concurrent.Semaphore
import java.util.concurrent.atomic.AtomicReference
import javax.imageio.ImageIO
Expand Down Expand Up @@ -102,6 +103,7 @@ class CreateImageAction : BaseAction() {
loadImages = false,
showMenubar = false
)
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")

val server = AppServer.getServer(event.project)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ import com.simiacryptus.skyenet.webui.application.ApplicationServer
import com.simiacryptus.skyenet.webui.session.SessionTask
import org.intellij.lang.annotations.Language
import org.slf4j.LoggerFactory
import java.text.SimpleDateFormat
import com.intellij.openapi.application.ApplicationManager as IntellijAppManager

class DiffChatAction : BaseAction() {
Expand Down Expand Up @@ -101,6 +102,7 @@ class DiffChatAction : BaseAction() {
) {
var selectionEnd = selectionEnd

SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
SessionProxyServer.agents[session] = object : CodeChatSocketManager(
session = session,
language = language,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ import java.awt.Dimension
import java.io.File
import java.nio.file.Files
import java.nio.file.Path
import java.text.SimpleDateFormat
import javax.swing.*

class DocumentedMassPatchAction : BaseAction() {
Expand Down Expand Up @@ -57,6 +58,7 @@ class DocumentedMassPatchAction : BaseAction() {
if (config == null) return

val session = Session.newGlobalID()
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
SessionProxyServer.chats[session] = DocumentedMassPatchServer(
config = config,
api = api,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ import com.simiacryptus.skyenet.webui.application.AppInfoData
import com.simiacryptus.skyenet.webui.application.ApplicationServer
import com.simiacryptus.skyenet.webui.chat.ChatSocketManager
import org.slf4j.LoggerFactory
import java.text.SimpleDateFormat

class GenericChatAction : BaseAction() {
override fun getActionUpdateThread() = ActionUpdateThread.BGT
Expand All @@ -33,6 +34,7 @@ class GenericChatAction : BaseAction() {
progress.text = "Setting up chat session..."

val session = Session.newGlobalID()
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
SessionProxyServer.agents[session] = ChatSocketManager(
session = session,
model = model,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ import java.awt.BorderLayout
import java.awt.Dimension
import java.nio.file.Files
import java.nio.file.Path
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.Semaphore
import java.util.concurrent.atomic.AtomicReference
Expand All @@ -54,10 +55,13 @@ class MassPatchAction : BaseAction() {
class SettingsUI {
@Name("Files to Process")
val filesToProcess = CheckBoxList<Path>()

@Name("AI Instruction")
val transformationMessage = JBTextArea(4, 40)

@Name("Recent Instructions")
val recentInstructions = JComboBox<String>()

@Name("Auto Apply")
val autoApply = JCheckBox("Auto Apply Changes")
}
Expand Down Expand Up @@ -122,27 +126,32 @@ class MassPatchAction : BaseAction() {
return
}

val session = Session.newGlobalID()
SessionProxyServer.chats[session] = MassPatchServer(config=config!!, api=api, autoApply = config.settings?.autoApply ?: false)
ApplicationServer.appInfoMap[session] = AppInfoData(
applicationName = "Code Chat",
singleInput = true,
stickyInput = false,
loadImages = false,
showMenubar = false
)
val session = Session.newGlobalID()
SessionProxyServer.metadataStorage.setSessionName(
null,
session,
"${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}"
)
SessionProxyServer.chats[session] = MassPatchServer(config = config!!, api = api, autoApply = config.settings?.autoApply ?: false)
ApplicationServer.appInfoMap[session] = AppInfoData(
applicationName = "Code Chat",
singleInput = true,
stickyInput = false,
loadImages = false,
showMenubar = false
)

val server = AppServer.getServer(event.project)
UITools.run(project, "Opening browser") {
Thread.sleep(500)
try {
val uri = server.server.uri.resolve("/#$session")
log.info("Opening browser to $uri")
browse(uri)
} catch (e: Throwable) {
log.warn("Error opening browser", e)
UITools.showErrorDialog(project, "Failed to open browser: ${e.message}", "Error")
}
Thread.sleep(500)
try {
val uri = server.server.uri.resolve("/#$session")
log.info("Opening browser to $uri")
browse(uri)
} catch (e: Throwable) {
log.warn("Error opening browser", e)
UITools.showErrorDialog(project, "Failed to open browser: ${e.message}", "Error")
}
}
} catch (e: Exception) {
log.error("Error in mass patch action", e)
Expand All @@ -156,7 +165,7 @@ class MassPatchAction : BaseAction() {

init {
this.title = title
// Set the default values for the UI elements from userSettings
// Set the default values for the UI elements from userSettings
settingsUI.transformationMessage.text = userSettings.transformationMessage
settingsUI.autoApply.isSelected = userSettings.autoApply
init()
Expand Down Expand Up @@ -215,43 +224,43 @@ class MassPatchServer(

return SimpleActor(
prompt = """
|You are a helpful AI that helps people with coding.
|
|Response should use one or more code patches in diff format within ```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
|```diff
| // Utility functions for example feature
| const b = 2;
| function exampleFunction() {
|- return b + 1;
|+ return b + 2;
| }
|```
|
|### tests/exampleUtils.test.js
|```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);
| });
| });
|```
|
|If needed, new files can be created by using code blocks labeled with the filename in the same manner.
""".trimMargin(),
|You are a helpful AI that helps people with coding.
|
|Response should use one or more code patches in diff format within ```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
|```diff
| // Utility functions for example feature
| const b = 2;
| function exampleFunction() {
|- return b + 1;
|+ return b + 2;
| }
|```
|
|### tests/exampleUtils.test.js
|```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);
| });
| });
|```
|
|If needed, new files can be created by using code blocks labeled with the filename in the same manner.
""".trimMargin(),
model = AppSettingsState.instance.smartModel.chatModel(),
temperature = AppSettingsState.instance.temperature,
)
Expand Down Expand Up @@ -289,11 +298,11 @@ class MassPatchServer(
?.entries?.joinToString("\n\n") { (path, code) ->
val extension = path.toString().split('.').lastOrNull()
"""
|# $path
|```$extension
|${code.let { /*escapeHtml4*/(it)/*.indent(" ")*/ }}
|```
""".trimMargin()
|# $path
|```$extension
|${code.let { /*escapeHtml4*/(it)/*.indent(" ")*/ }}
|```
""".trimMargin()
}
val fileTask = ui.newTask(false).apply {
tabs[path.toString()] = placeholder
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import com.simiacryptus.skyenet.webui.application.ApplicationServer
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
import java.text.SimpleDateFormat
import java.util.*

/**
Expand Down Expand Up @@ -72,6 +73,7 @@ class MultiCodeChatAction : BaseAction() {
progress.isIndeterminate = true
progress.text = "Setting up chat session..."
val session = Session.newGlobalID()
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
SessionProxyServer.chats[session] = PatchApp(root.toFile(), { codeSummary() }, codeFiles)
ApplicationServer.appInfoMap[session] = AppInfoData(
applicationName = "Code Chat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ import com.simiacryptus.skyenet.webui.application.ApplicationServer
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
import java.text.SimpleDateFormat
import java.util.*
import java.util.concurrent.Semaphore
import java.util.concurrent.atomic.AtomicReference
Expand Down Expand Up @@ -59,6 +60,7 @@ class MultiDiffChatAction : BaseAction() {
}
val initialFiles = getFiles(virtualFiles, root)
val session = Session.newGlobalID()
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
SessionProxyServer.chats[session] = PatchApp(root.toFile(), initialFiles)
ApplicationServer.appInfoMap[session] = AppInfoData(
applicationName = "Code Chat",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import com.simiacryptus.util.JsonUtil.toJson
import org.slf4j.LoggerFactory
import java.io.File
import java.nio.file.Path
import java.text.SimpleDateFormat
import java.util.concurrent.Semaphore
import java.util.concurrent.atomic.AtomicReference

Expand All @@ -64,6 +65,7 @@ class MultiStepPatchAction : BaseAction() {
if (null != storage && null != selectedFile) {
DataStorage.sessionPaths[session] = selectedFile.toFile
}
SessionProxyServer.metadataStorage.setSessionName(null, session, "${javaClass.simpleName} @ ${SimpleDateFormat("HH:mm:ss").format(System.currentTimeMillis())}")
SessionProxyServer.chats[session] = AutoDevApp(event = e)
ApplicationServer.appInfoMap[session] = AppInfoData(
applicationName = "Code Chat",
Expand Down
Loading

0 comments on commit bd90adf

Please sign in to comment.