mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-08-28 19:11:03 +08:00
refactor(jetbrains): share CLI tool tag parsing
This commit is contained in:
+3
-10
@@ -14,6 +14,7 @@ import ai.kilocode.client.ui.layout.HAlign
|
||||
import ai.kilocode.client.ui.layout.Stack
|
||||
import ai.kilocode.client.ui.layout.VAlign
|
||||
import ai.kilocode.client.ui.layout.align
|
||||
import ai.kilocode.cli.KiloCliParser
|
||||
import ai.kilocode.log.KiloLog
|
||||
import com.intellij.openapi.Disposable
|
||||
import com.intellij.openapi.editor.EditorFactory
|
||||
@@ -539,19 +540,11 @@ internal data class Target(
|
||||
internal fun target(tool: Tool): Target? {
|
||||
val out = output(tool)
|
||||
if (out.isBlank()) return null
|
||||
val path = tag(out, "path") ?: return null
|
||||
val type = tag(out, "type") ?: return null
|
||||
val path = KiloCliParser.tag(out, "path") ?: return null
|
||||
val type = KiloCliParser.tag(out, "type") ?: return null
|
||||
return Target(path, type.lowercase())
|
||||
}
|
||||
|
||||
private fun tag(text: String, name: String): String? =
|
||||
Regex("<$name>\\s*([\\s\\S]*?)\\s*</$name>")
|
||||
.find(text)
|
||||
?.groupValues
|
||||
?.getOrNull(1)
|
||||
?.trim()
|
||||
?.takeIf { it.isNotBlank() }
|
||||
|
||||
private fun shellTitle(tool: Tool): String =
|
||||
tool.input["description"]?.takeIf { it.isNotBlank() }
|
||||
?: tool.metadata["description"]?.takeIf { it.isNotBlank() }
|
||||
|
||||
+27
@@ -0,0 +1,27 @@
|
||||
package ai.kilocode.client.session.views.tool
|
||||
|
||||
import ai.kilocode.cli.KiloCliParser
|
||||
import kotlin.test.Test
|
||||
import kotlin.test.assertEquals
|
||||
import kotlin.test.assertNull
|
||||
|
||||
class KiloCliParserTest {
|
||||
@Test
|
||||
fun `tag extracts trimmed tool xml value`() {
|
||||
val text = """
|
||||
<path>
|
||||
/tmp/example.txt
|
||||
</path>
|
||||
<type>file</type>
|
||||
""".trimIndent()
|
||||
|
||||
assertEquals("/tmp/example.txt", KiloCliParser.tag(text, "path"))
|
||||
assertEquals("file", KiloCliParser.tag(text, "type"))
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `tag returns null for blank or missing value`() {
|
||||
assertNull(KiloCliParser.tag("<path> </path>", "path"))
|
||||
assertNull(KiloCliParser.tag("<type>file</type>", "path"))
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package ai.kilocode.cli
|
||||
|
||||
object KiloCliParser {
|
||||
fun tag(text: String, name: String): String? =
|
||||
Regex("<$name>\\s*([\\s\\S]*?)\\s*</$name>")
|
||||
.find(text)
|
||||
?.groupValues
|
||||
?.getOrNull(1)
|
||||
?.trim()
|
||||
?.takeIf { it.isNotBlank() }
|
||||
}
|
||||
Reference in New Issue
Block a user