Skip to content
Merged
Show file tree
Hide file tree
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
79 changes: 71 additions & 8 deletions crates/jp_cli/src/cmd/conversation/print.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
use jp_config::style::typewriter::DelayDuration;
use jp_config::{
conversation::tool::style::{self, DisplayStyleConfig, InlineResults, ParametersStyle},
style::{reasoning::ReasoningDisplayConfig, typewriter::DelayDuration},
};
use jp_workspace::ConversationHandle;

use crate::{
Expand All @@ -7,6 +10,22 @@ use crate::{
render::{ConfigSource, TurnRenderer},
};

/// Brief-mode tool display style: no arguments, no results, no file links.
const BRIEF_TOOL_STYLE: DisplayStyleConfig = DisplayStyleConfig {
hidden: false,
parameters: ParametersStyle::Off,
inline_results: InlineResults::Off,
results_file_link: style::LinkStyle::Off,
};

/// Full-mode tool display style: everything visible, nothing truncated.
const FULL_TOOL_STYLE: DisplayStyleConfig = DisplayStyleConfig {
hidden: false,
parameters: ParametersStyle::Json,
inline_results: InlineResults::Full,
results_file_link: style::LinkStyle::Full,
};

#[derive(Debug, clap::Args)]
pub(crate) struct Print {
#[command(flatten)]
Expand All @@ -27,6 +46,25 @@ pub(crate) struct Print {
/// config for all turns.
#[arg(long, default_value_t = false)]
current_config: bool,

/// Output style preset.
///
/// - `brief`: Hide reasoning, tool arguments, and tool results. Shows
/// only user messages, assistant messages, and tool call headers.
/// - `full`: Show everything including reasoning, tool arguments, and
/// untruncated tool results.
#[arg(long, short = 's', value_enum)]
style: Option<PrintStyle>,
}

/// Output style presets for `jp conversation print`.
#[derive(Debug, Clone, Copy, PartialEq, Eq, clap::ValueEnum)]
pub(crate) enum PrintStyle {
/// Hide reasoning, tool arguments, and tool results.
Brief,
/// Show everything: full reasoning, tool arguments, and untruncated
/// tool results.
Full,
}

impl Print {
Expand All @@ -44,7 +82,7 @@ impl Print {
};

for handle in handles {
Self::print_conversation(ctx, handle, &selection, self.current_config)?;
Self::print_conversation(ctx, handle, &selection, self.current_config, self.style)?;
}
ctx.printer.println("");
ctx.printer.flush();
Expand All @@ -56,6 +94,7 @@ impl Print {
handle: &ConversationHandle,
selection: &TurnSelection,
current_config: bool,
print_style: Option<PrintStyle>,
) -> Output {
let events = ctx.workspace.events(handle)?.clone();
let cfg = ctx.config();
Expand All @@ -65,21 +104,27 @@ impl Print {
.unwrap_or(ctx.workspace.root())
.to_path_buf();

let source = if current_config {
let source = if current_config || print_style.is_some() {
ConfigSource::Fixed
} else {
ConfigSource::PerTurn
};

// Disable typewriter delays — print replays content instantly.
let mut style = cfg.style.clone();
style.typewriter.text_delay = DelayDuration::instant();
style.typewriter.code_delay = DelayDuration::instant();
let mut render_style = cfg.style.clone();
render_style.typewriter.text_delay = DelayDuration::instant();
render_style.typewriter.code_delay = DelayDuration::instant();

let mut tools_config = cfg.conversation.tools.clone();

if let Some(preset) = print_style {
apply_style_preset(preset, &mut render_style, &mut tools_config);
}

let mut renderer = TurnRenderer::new(
ctx.printer.clone(),
style,
cfg.conversation.tools.clone(),
render_style,
tools_config,
root,
ctx.term.is_tty,
source,
Expand Down Expand Up @@ -117,6 +162,24 @@ impl Print {
}
}

/// Apply a style preset to the rendering config and tool config.
fn apply_style_preset(
preset: PrintStyle,
style: &mut jp_config::style::StyleConfig,
tools_config: &mut jp_config::conversation::tool::ToolsConfig,
) {
let (reasoning_display, tool_style) = match preset {
PrintStyle::Brief => (ReasoningDisplayConfig::Hidden, BRIEF_TOOL_STYLE),
PrintStyle::Full => (ReasoningDisplayConfig::Full, FULL_TOOL_STYLE),
};

style.reasoning.display = reasoning_display;
tools_config.defaults.style = tool_style.clone();
for (_name, tool) in tools_config.iter_mut() {
tool.style = Some(tool_style.clone());
}
}

/// How to select which turns to print.
enum TurnSelection {
/// Print all turns.
Expand Down
Loading
Loading