mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-30 17:14:40 +08:00
fix(jetbrains): send git changes as data file
This commit is contained in:
@@ -0,0 +1,5 @@
|
||||
---
|
||||
"@kilocode/kilo-jetbrains": patch
|
||||
---
|
||||
|
||||
Fix @git-changes mentions causing JetBrains chat sessions to fail.
|
||||
+17
@@ -1714,6 +1714,23 @@ class KiloCliDataParserTest {
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `buildPromptJson - data file part without source omits source metadata`() {
|
||||
val prompt = PromptDto(parts = listOf(PromptPartDto(
|
||||
type = "file",
|
||||
mime = "text/plain",
|
||||
url = "data:text/plain;charset=utf-8,diff%20content",
|
||||
filename = "git-changes.txt",
|
||||
)))
|
||||
|
||||
val result = KiloCliDataParser.buildPromptJson(prompt)
|
||||
|
||||
assertEquals(
|
||||
"""{"parts":[{"type":"file","mime":"text/plain","url":"data:text/plain;charset=utf-8,diff%20content","filename":"git-changes.txt"}]}""",
|
||||
result,
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `buildCommandJson - file part includes source metadata`() {
|
||||
val prompt = PromptDto(parts = listOf(PromptPartDto(
|
||||
|
||||
+2
-4
@@ -30,7 +30,7 @@ fun gitChangesPart(text: String, diff: String?): PromptPartDto? {
|
||||
val raw = spec.token
|
||||
val start = text.mentionStart(raw) ?: return null
|
||||
val value = diff?.takeIf { it.isNotBlank() } ?: return null
|
||||
return dataPart(spec.filename, value, source("resource", raw, start, uri = spec.uri))
|
||||
return dataPart(spec.filename, value)
|
||||
}
|
||||
|
||||
private fun String.mentionStart(token: String): Int? {
|
||||
@@ -48,10 +48,8 @@ private fun dataPart(name: String, text: String, source: PartSourceDto? = null):
|
||||
return PromptPartDto(type = "file", mime = "text/plain", url = "data:text/plain;charset=utf-8,$data", filename = name, source = source)
|
||||
}
|
||||
|
||||
private fun source(type: String, token: String, start: Int, path: String? = null, uri: String? = null) = PartSourceDto(
|
||||
private fun source(type: String, token: String, start: Int, path: String? = null) = PartSourceDto(
|
||||
type = type,
|
||||
text = PartSourceTextDto(value = token, start = start.toDouble(), end = (start + token.length).toDouble()),
|
||||
path = path,
|
||||
uri = uri,
|
||||
clientName = if (type == "resource") "jetbrains" else null,
|
||||
)
|
||||
|
||||
+1
-6
@@ -49,12 +49,7 @@ class PromptMentionPartsTest : BasePlatformTestCase() {
|
||||
assertEquals("text/plain", part.mime)
|
||||
assertEquals(MentionAction.GIT_CHANGES.filename, part.filename)
|
||||
assertEquals("data:text/plain;charset=utf-8,hello%20world%2Bplus", part.url)
|
||||
assertEquals("resource", part.source?.type)
|
||||
assertEquals(MentionAction.GIT_CHANGES.uri, part.source?.uri)
|
||||
assertEquals("jetbrains", part.source?.clientName)
|
||||
assertEquals(MentionAction.GIT_CHANGES.token, part.source?.text?.value)
|
||||
assertEquals(7.0, part.source?.text?.start)
|
||||
assertEquals(19.0, part.source?.text?.end)
|
||||
assertNull(part.source)
|
||||
}
|
||||
|
||||
fun `test gitChangesPart ignores missing blank and non boundary matches`() {
|
||||
|
||||
Reference in New Issue
Block a user