Skip to content

Commit d0c61c5

Browse files
committed
feat(agent): skip tool result rendering for live terminal #453
Pass metadata to renderers and prevent duplicate rendering when a live terminal session is active. This avoids showing tool results already displayed in the LiveTerminal UI.
1 parent 9d1511b commit d0c61c5

File tree

5 files changed

+21
-9
lines changed

5 files changed

+21
-9
lines changed

mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/executor/CodingAgentExecutor.kt

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -275,11 +275,14 @@ class CodingAgentExecutor(
275275
val contentHandlerResult = checkForLongContent(toolName, fullOutput ?: "", executionResult)
276276
val displayOutput = contentHandlerResult?.content ?: fullOutput
277277

278-
// **关键改动**: 检查是否是 live session,如果是则跳过渲染 (输出已经在 LiveTerminal 中显示)
279-
val isLiveSession = executionResult.metadata["isLiveSession"] == "true"
280-
if (!isLiveSession) {
281-
renderer.renderToolResult(toolName, stepResult.success, stepResult.result, displayOutput)
282-
}
278+
// **关键改动**: 传递 metadata 给 renderer,用于检查是否是 live session
279+
renderer.renderToolResult(
280+
toolName,
281+
stepResult.success,
282+
stepResult.result,
283+
displayOutput,
284+
executionResult.metadata
285+
)
283286

284287
val currentToolType = toolName.toToolType()
285288
if ((currentToolType == ToolType.WriteFile) && executionResult.isSuccess) {

mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/render/CodingAgentRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ interface CodingAgentRenderer {
1313

1414
// Tool execution methods
1515
fun renderToolCall(toolName: String, paramsStr: String)
16-
fun renderToolResult(toolName: String, success: Boolean, output: String?, fullOutput: String?)
16+
fun renderToolResult(toolName: String, success: Boolean, output: String?, fullOutput: String?, metadata: Map<String, String> = emptyMap())
1717

1818
// Status and completion methods
1919
fun renderTaskComplete()

mpp-core/src/commonMain/kotlin/cc/unitmesh/agent/render/DefaultCodingAgentRenderer.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ class DefaultCodingAgentRenderer : BaseRenderer() {
4747
println("🔧 /$toolName $paramsStr")
4848
}
4949

50-
override fun renderToolResult(toolName: String, success: Boolean, output: String?, fullOutput: String?) {
50+
override fun renderToolResult(toolName: String, success: Boolean, output: String?, fullOutput: String?, metadata: Map<String, String>) {
5151
val icon = if (success) "" else ""
5252
print(" $icon $toolName")
5353

mpp-core/src/jsMain/kotlin/cc/unitmesh/agent/RendererExports.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ class JsRendererAdapter(private val jsRenderer: JsCodingAgentRenderer) : CodingA
7575
jsRenderer.renderToolCall(toolName, paramsStr)
7676
}
7777

78-
override fun renderToolResult(toolName: String, success: Boolean, output: String?, fullOutput: String?) {
78+
override fun renderToolResult(toolName: String, success: Boolean, output: String?, fullOutput: String?, metadata: Map<String, String>) {
7979
jsRenderer.renderToolResult(toolName, success, output, fullOutput)
8080
}
8181

mpp-ui/src/commonMain/kotlin/cc/unitmesh/devins/ui/compose/agent/ComposeRenderer.kt

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,19 @@ class ComposeRenderer : BaseRenderer() {
211211
toolName: String,
212212
success: Boolean,
213213
output: String?,
214-
fullOutput: String?
214+
fullOutput: String?,
215+
metadata: Map<String, String>
215216
) {
216217
val summary = formatToolResultSummary(toolName, success, output)
217218

219+
// Check if this was a live terminal session - skip rendering if so
220+
val isLiveSession = metadata["isLiveSession"] == "true"
221+
if (isLiveSession) {
222+
// Live terminal already rendered - just mark tool call as complete
223+
_currentToolCall = null
224+
return
225+
}
226+
218227
// For shell commands, use special terminal output rendering
219228
val toolType = toolName.toToolType()
220229
if (toolType == ToolType.Shell && output != null) {

0 commit comments

Comments
 (0)