Skip to content

Commit cf0d810

Browse files
committed
show available summary instead regenerate it
1 parent da2a89f commit cf0d810

File tree

2 files changed

+35
-8
lines changed

2 files changed

+35
-8
lines changed

crates/q_chat/src/conversation_state.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,10 @@ impl ConversationState {
135135
}
136136
}
137137

138+
pub fn latest_summary(&self) -> Option<&str> {
139+
self.latest_summary.as_deref()
140+
}
141+
138142
pub fn history(&self) -> &VecDeque<(UserMessage, AssistantMessage)> {
139143
&self.history
140144
}

crates/q_chat/src/lib.rs

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1846,14 +1846,37 @@ impl ChatContext {
18461846
)?;
18471847

18481848
if expand {
1849-
self.compact_history(
1850-
Some(tool_uses.clone()),
1851-
pending_tool_index,
1852-
None,
1853-
true,
1854-
false,
1855-
)
1856-
.await?;
1849+
let existing_summary =
1850+
self.conversation_state.latest_summary().map(|s| s.to_owned());
1851+
if let Some(summary) = existing_summary {
1852+
// Add a border around the summary for better visual separation
1853+
let terminal_width = self.terminal_width();
1854+
let border = "═".repeat(terminal_width.min(80));
1855+
execute!(
1856+
self.output,
1857+
style::Print("\n"),
1858+
style::SetForegroundColor(Color::Cyan),
1859+
style::Print(&border),
1860+
style::Print("\n"),
1861+
style::SetAttribute(Attribute::Bold),
1862+
style::Print(" CONVERSATION SUMMARY"),
1863+
style::Print("\n"),
1864+
style::Print(&border),
1865+
style::SetAttribute(Attribute::Reset),
1866+
style::Print("\n\n"),
1867+
style::Print(&summary),
1868+
style::Print("\n\n")
1869+
)?;
1870+
} else {
1871+
self.compact_history(
1872+
Some(tool_uses.clone()),
1873+
pending_tool_index,
1874+
None,
1875+
true,
1876+
false,
1877+
)
1878+
.await?;
1879+
}
18571880
}
18581881

18591882
execute!(self.output, style::Print("\n"))?;

0 commit comments

Comments
 (0)