Skip to content
This repository was archived by the owner on Jul 22, 2026. It is now read-only.
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 39 additions & 15 deletions src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2069,9 +2069,9 @@ impl PromptState {
exit_code,
stdout: _,
stderr: _,
aggregated_output: _,
aggregated_output,
duration: _,
formatted_output: _,
formatted_output,
process_id: _,
completed_at_ms: _,
status,
Expand All @@ -2093,20 +2093,25 @@ impl PromptState {

// For the non-terminal fallback path the per-chunk delta handler now
// accumulates silently (see exec_command_output_delta). Emit the full
// buffer here, exactly once, as a single content block. Skip the emission
// entirely when the command produced no output, so we don't surface an
// empty fenced code block to the client.
if !supports_terminal && !active_command.output.is_empty() {
// buffer here, exactly once, as a single content block. Some commands can
// reach this point without deltas even though the end event carries output,
// so fall back to the final formatted/aggregated output before deciding
// there is nothing to display.
let output = if active_command.output.is_empty() {
[&formatted_output, &aggregated_output]
.into_iter()
.find(|output| !output.is_empty())
.map(String::as_str)
.unwrap_or_default()
} else {
active_command.output.as_str()
};

if !supports_terminal && !output.is_empty() {
let content = match active_command.file_extension.as_deref() {
Some("md") => active_command.output.clone(),
Some(ext) => format!(
"```{ext}\n{}\n```\n",
active_command.output.trim_end_matches('\n')
),
None => format!(
"```sh\n{}\n```\n",
active_command.output.trim_end_matches('\n')
),
Some("md") => output.to_owned(),
Some(ext) => format!("```{ext}\n{}\n```\n", output.trim_end_matches('\n')),
None => format!("```sh\n{}\n```\n", output.trim_end_matches('\n')),
};
fields = fields.content(vec![content.into()]);
}
Expand Down Expand Up @@ -5177,6 +5182,25 @@ mod tests {
"expected 2 completed ToolCallUpdate notifications, got {completed_updates:?}"
);

let completed_content: std::collections::HashSet<_> = completed_updates
.iter()
.filter_map(|update| {
let content = update.fields.content.as_ref()?.first()?;
match content {
ToolCallContent::Content(Content {
content: ContentBlock::Text(TextContent { text, .. }),
..
}) => Some(text.as_str()),
_ => None,
}
})
.collect();
assert!(
completed_content.contains("```sh\na\n```\n")
&& completed_content.contains("```sh\nb\n```\n"),
"completed updates should include end-event output, got {completed_updates:?}"
);

// The completed updates should reference the same tool_call_ids as the begins.
let begin_ids: std::collections::HashSet<_> = tool_calls
.iter()
Expand Down
Loading