fix(cli-run): deduplicate tool headers and message counter resets on repeated events

Guard against duplicate tool header/output rendering when both tool.execute
and message.part.updated fire for the same tool, and prevent message counter
resets when message.updated fires multiple times for the same assistant message.

🤖 Generated with [OhMyOpenCode](https://github.com/code-yeongyu/oh-my-opencode) assistance
This commit is contained in:
YeonGyu-Kim
2026-02-18 02:01:08 +09:00
parent 3313ec3e4f
commit d9751bd5cb
3 changed files with 206 additions and 10 deletions
+20 -10
View File
@@ -187,6 +187,7 @@ function handleToolPart(
const status = part.state?.status
if (status === "running") {
if (state.currentTool !== null) return
state.currentTool = toolName
const header = formatToolHeader(toolName, part.state?.input ?? {})
const suffix = header.description ? ` ${pc.dim(header.description)}` : ""
@@ -195,6 +196,7 @@ function handleToolPart(
}
if (status === "completed" || status === "error") {
if (state.currentTool === null) return
const output = part.state?.output || ""
if (output.trim()) {
process.stdout.write(pc.dim(` ${displayChars.treeEnd} output \n`))
@@ -216,7 +218,7 @@ export function handleMessageUpdated(ctx: RunContext, payload: EventPayload, sta
state.currentMessageRole = props?.info?.role ?? null
const messageID = props?.info?.id
const messageID = props?.info?.id ?? null
const role = props?.info?.role
if (messageID && role) {
state.messageRoleById[messageID] = role
@@ -224,15 +226,19 @@ export function handleMessageUpdated(ctx: RunContext, payload: EventPayload, sta
if (props?.info?.role !== "assistant") return
state.hasReceivedMeaningfulWork = true
state.messageCount++
state.lastPartText = ""
state.lastReasoningText = ""
state.hasPrintedThinkingLine = false
state.lastThinkingSummary = ""
state.textAtLineStart = true
state.thinkingAtLineStart = false
closeThinkBlockIfNeeded(state)
const isNewMessage = !messageID || messageID !== state.currentMessageId
if (isNewMessage) {
state.currentMessageId = messageID
state.hasReceivedMeaningfulWork = true
state.messageCount++
state.lastPartText = ""
state.lastReasoningText = ""
state.hasPrintedThinkingLine = false
state.lastThinkingSummary = ""
state.textAtLineStart = true
state.thinkingAtLineStart = false
closeThinkBlockIfNeeded(state)
}
const agent = props?.info?.agent ?? null
const model = props?.info?.modelID ?? null
@@ -253,6 +259,8 @@ export function handleToolExecute(ctx: RunContext, payload: EventPayload, state:
closeThinkBlockIfNeeded(state)
if (state.currentTool !== null) return
const toolName = props?.name || "unknown"
state.currentTool = toolName
const header = formatToolHeader(toolName, props?.input ?? {})
@@ -270,6 +278,8 @@ export function handleToolResult(ctx: RunContext, payload: EventPayload, state:
closeThinkBlockIfNeeded(state)
if (state.currentTool === null) return
const output = props?.output || ""
if (output.trim()) {
process.stdout.write(pc.dim(` ${displayChars.treeEnd} output \n`))