Skip to content

Commit 3a96cec

Browse files
committed
cr
1 parent a6f1d56 commit 3a96cec

File tree

1 file changed

+68
-80
lines changed
  • crates/chat-cli/src/cli/chat

1 file changed

+68
-80
lines changed

crates/chat-cli/src/cli/chat/mod.rs

Lines changed: 68 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -1621,14 +1621,14 @@ impl ChatContext {
16211621
style::SetForegroundColor(Color::DarkYellow),
16221622
style::Print("\n 🔧 Hooks:\n")
16231623
)?;
1624-
Self::print_hook_section(
1624+
print_hook_section(
16251625
&mut self.output,
16261626
&context_manager.global_config.hooks,
16271627
HookTrigger::ConversationStart,
16281628
)
16291629
.map_err(map_chat_error)?;
16301630

1631-
Self::print_hook_section(
1631+
print_hook_section(
16321632
&mut self.output,
16331633
&context_manager.global_config.hooks,
16341634
HookTrigger::PerPrompt,
@@ -1682,13 +1682,13 @@ impl ChatContext {
16821682
style::SetForegroundColor(Color::DarkYellow),
16831683
style::Print(" 🔧 Hooks:\n")
16841684
)?;
1685-
Self::print_hook_section(
1685+
print_hook_section(
16861686
&mut self.output,
16871687
&context_manager.profile_config.hooks,
16881688
HookTrigger::ConversationStart,
16891689
)
16901690
.map_err(map_chat_error)?;
1691-
Self::print_hook_section(
1691+
print_hook_section(
16921692
&mut self.output,
16931693
&context_manager.profile_config.hooks,
16941694
HookTrigger::PerPrompt,
@@ -1773,42 +1773,30 @@ impl ChatContext {
17731773
self.output,
17741774
style::Print(format!("\nTotal: ~{} tokens\n\n", total_tokens)),
17751775
)?;
1776+
}
17761777

1777-
// Show last cached conversation summary if available, otherwise regenerate it
1778-
if expand {
1779-
if let Some(summary) =
1780-
self.conversation_state.latest_summary().map(|s| s.to_owned())
1781-
{
1782-
let border = "═".repeat(self.terminal_width().min(80));
1783-
execute!(
1784-
self.output,
1785-
style::Print("\n"),
1786-
style::SetForegroundColor(Color::Cyan),
1787-
style::Print(&border),
1788-
style::Print("\n"),
1789-
style::SetAttribute(Attribute::Bold),
1790-
style::Print(" CONVERSATION SUMMARY"),
1791-
style::Print("\n"),
1792-
style::Print(&border),
1793-
style::SetAttribute(Attribute::Reset),
1794-
style::Print("\n\n"),
1795-
style::Print(&summary),
1796-
style::Print("\n\n")
1797-
)?;
1798-
} else {
1799-
self.compact_history(
1800-
Some(tool_uses.clone()),
1801-
pending_tool_index,
1802-
None,
1803-
true,
1804-
false,
1805-
)
1806-
.await?;
1807-
}
1778+
// Show last cached conversation summary if available, otherwise regenerate it
1779+
if expand {
1780+
if let Some(summary) = self.conversation_state.latest_summary().map(|s| s.to_owned()) {
1781+
let border = "═".repeat(self.terminal_width().min(80));
1782+
execute!(
1783+
self.output,
1784+
style::Print("\n"),
1785+
style::SetForegroundColor(Color::Cyan),
1786+
style::Print(&border),
1787+
style::Print("\n"),
1788+
style::SetAttribute(Attribute::Bold),
1789+
style::Print(" CONVERSATION SUMMARY"),
1790+
style::Print("\n"),
1791+
style::Print(&border),
1792+
style::SetAttribute(Attribute::Reset),
1793+
style::Print("\n\n"),
1794+
style::Print(&summary),
1795+
style::Print("\n\n")
1796+
)?;
18081797
}
1809-
1810-
execute!(self.output, style::Print("\n"))?;
18111798
}
1799+
execute!(self.output, style::Print("\n"))?;
18121800
},
18131801
command::ContextSubcommand::Add { global, force, paths } => {
18141802
match context_manager.add_paths(paths.clone(), global, force).await {
@@ -2066,13 +2054,13 @@ impl ChatContext {
20662054
style::SetAttribute(Attribute::Reset),
20672055
)?;
20682056

2069-
Self::print_hook_section(
2057+
print_hook_section(
20702058
&mut self.output,
20712059
&context_manager.global_config.hooks,
20722060
HookTrigger::ConversationStart,
20732061
)
20742062
.map_err(map_chat_error)?;
2075-
Self::print_hook_section(
2063+
print_hook_section(
20762064
&mut self.output,
20772065
&context_manager.global_config.hooks,
20782066
HookTrigger::PerPrompt,
@@ -2087,13 +2075,13 @@ impl ChatContext {
20872075
style::SetAttribute(Attribute::Reset),
20882076
)?;
20892077

2090-
Self::print_hook_section(
2078+
print_hook_section(
20912079
&mut self.output,
20922080
&context_manager.profile_config.hooks,
20932081
HookTrigger::ConversationStart,
20942082
)
20952083
.map_err(map_chat_error)?;
2096-
Self::print_hook_section(
2084+
print_hook_section(
20972085
&mut self.output,
20982086
&context_manager.profile_config.hooks,
20992087
HookTrigger::PerPrompt,
@@ -2670,45 +2658,6 @@ impl ChatContext {
26702658
})
26712659
}
26722660

2673-
// Prints hook configuration grouped by trigger: conversation sesiion start or per user message
2674-
fn print_hook_section(output: &mut impl Write, hooks: &HashMap<String, Hook>, trigger: HookTrigger) -> Result<()> {
2675-
let section = match trigger {
2676-
HookTrigger::ConversationStart => "On Session Start",
2677-
HookTrigger::PerPrompt => "Per User Message",
2678-
};
2679-
let hooks: Vec<(&String, &Hook)> = hooks.iter().filter(|(_, h)| h.trigger == trigger).collect();
2680-
2681-
queue!(
2682-
output,
2683-
style::SetForegroundColor(Color::Cyan),
2684-
style::Print(format!(" {section}:\n")),
2685-
style::SetForegroundColor(Color::Reset),
2686-
)?;
2687-
2688-
if hooks.is_empty() {
2689-
queue!(
2690-
output,
2691-
style::SetForegroundColor(Color::DarkGrey),
2692-
style::Print(" <none>\n"),
2693-
style::SetForegroundColor(Color::Reset)
2694-
)?;
2695-
} else {
2696-
for (name, hook) in hooks {
2697-
if hook.disabled {
2698-
queue!(
2699-
output,
2700-
style::SetForegroundColor(Color::DarkGrey),
2701-
style::Print(format!(" {} (disabled)\n", name)),
2702-
style::SetForegroundColor(Color::Reset)
2703-
)?;
2704-
} else {
2705-
queue!(output, style::Print(format!(" {}\n", name)),)?;
2706-
}
2707-
}
2708-
}
2709-
Ok(())
2710-
}
2711-
27122661
async fn tool_use_execute(&mut self, mut tool_uses: Vec<QueuedTool>) -> Result<ChatState, ChatError> {
27132662
// Verify tools have permissions.
27142663
for (index, tool) in tool_uses.iter_mut().enumerate() {
@@ -3329,6 +3278,45 @@ impl ChatContext {
33293278
}
33303279
}
33313280

3281+
/// Prints hook configuration grouped by trigger: conversation sesiion start or per user message
3282+
fn print_hook_section(output: &mut impl Write, hooks: &HashMap<String, Hook>, trigger: HookTrigger) -> Result<()> {
3283+
let section = match trigger {
3284+
HookTrigger::ConversationStart => "On Session Start",
3285+
HookTrigger::PerPrompt => "Per User Message",
3286+
};
3287+
let hooks: Vec<(&String, &Hook)> = hooks.iter().filter(|(_, h)| h.trigger == trigger).collect();
3288+
3289+
queue!(
3290+
output,
3291+
style::SetForegroundColor(Color::Cyan),
3292+
style::Print(format!(" {section}:\n")),
3293+
style::SetForegroundColor(Color::Reset),
3294+
)?;
3295+
3296+
if hooks.is_empty() {
3297+
queue!(
3298+
output,
3299+
style::SetForegroundColor(Color::DarkGrey),
3300+
style::Print(" <none>\n"),
3301+
style::SetForegroundColor(Color::Reset)
3302+
)?;
3303+
} else {
3304+
for (name, hook) in hooks {
3305+
if hook.disabled {
3306+
queue!(
3307+
output,
3308+
style::SetForegroundColor(Color::DarkGrey),
3309+
style::Print(format!(" {} (disabled)\n", name)),
3310+
style::SetForegroundColor(Color::Reset)
3311+
)?;
3312+
} else {
3313+
queue!(output, style::Print(format!(" {}\n", name)),)?;
3314+
}
3315+
}
3316+
}
3317+
Ok(())
3318+
}
3319+
33323320
#[derive(Debug)]
33333321
struct ToolUseEventBuilder {
33343322
pub conversation_id: String,

0 commit comments

Comments
 (0)