fix(jetbrains): send git changes as data file

This commit is contained in:
kirillk
2026-06-22 15:14:26 -04:00
parent f0ea4b66f6
commit cfb7006e88
4 changed files with 25 additions and 10 deletions
@@ -0,0 +1,5 @@
---
"@kilocode/kilo-jetbrains": patch
---
Fix @git-changes mentions causing JetBrains chat sessions to fail.
@@ -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(
@@ -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,
)
@@ -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`() {