Skip to content
Merged
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
19 changes: 12 additions & 7 deletions src/tool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,30 +195,26 @@ pub enum DisplayHint {
///
/// Render the payload as-is. This is what every tool gets when it does not
/// call [`ToolOutput::with_hint`].
#[serde(rename = "text")]
Text,

/// A unified diff — render with `+`/`-` line coloring.
///
/// Intended for Edit/MultiEdit/Patch tools whose payload is a
/// `diff`-formatted string. A consumer that supports diff rendering parses
/// the payload as a unified diff; one that does not falls back to `Text`.
#[serde(rename = "diff")]
Diff,

/// Structured JSON — pretty-print / syntax-highlight.
///
/// The payload is a JSON-encoded string the consumer may parse and
/// re-format. If parsing fails the consumer falls back to `Text`.
#[serde(rename = "json")]
Json,

/// Syntax-highlighted source code in the given language.
///
/// `language` is a free-form hint (e.g. `"rust"`, `"python"`, `"json"`),
/// matching the identifiers used by common highlighters. A consumer that
/// does not highlight renders the payload as plain `Text`.
#[serde(rename = "code")]
Code {
/// The source language identifier (lowercase convention, e.g. `"rust"`).
language: String,
Expand All @@ -231,7 +227,6 @@ pub enum DisplayHint {
/// one-line output preview in Normal verbosity, or collapse the block).
/// Intended for tools whose output duplicates content the user already saw
/// (a Read echoing a large file) or is machine-only.
#[serde(rename = "suppress")]
Suppress,

/// Structured Markdown the tool authored as Markdown.
Expand All @@ -243,7 +238,6 @@ pub enum DisplayHint {
/// — any text *could* be rendered as Markdown, but `Markdown` signals the
/// tool's positive intent. A consumer that does not render Markdown falls
/// back to `Text`.
#[serde(rename = "markdown")]
Markdown,
}

Expand Down Expand Up @@ -2011,6 +2005,18 @@ mod tests {
);
}

#[test]
fn soft_error_preserves_display_hint() {
let soft_err = ToolOutput::error_text("conflict in foo.rs").with_hint(DisplayHint::Diff);
assert!(soft_err.is_error, "fixture is a soft error");
let result: ToolDispatchResult = soft_err.into();
assert_eq!(
result.display_hint,
Some(DisplayHint::Diff),
"soft-error outputs preserve their hint (only hard errors / panics drop it)"
);
}

/// A stub tool that returns a fixed hinted `ToolOutput`.
struct HintedTool {
name: &'static str,
Expand Down Expand Up @@ -2061,7 +2067,6 @@ mod tests {
}
}

#[cfg(feature = "testing")]
#[cfg(feature = "testing")]
fn hinted_dispatch_setup(
tool_name: &'static str,
Expand Down