Skip to content

Commit 17fbe84

Browse files
feat: show usage on completion (tailcallhq#1448)
Co-authored-by: Tushar Mathur <tusharmath@gmail.com>
1 parent 2a1df21 commit 17fbe84

2 files changed

Lines changed: 20 additions & 4 deletions

File tree

crates/forge_main/src/info.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ pub enum Section {
1515
Items(String, Option<String>),
1616
}
1717

18+
#[derive(Default)]
1819
pub struct Info {
1920
sections: Vec<Section>,
2021
}
@@ -118,10 +119,12 @@ impl From<&Metrics> for Info {
118119
Some(d) => humantime::format_duration(Duration::from_secs(d.as_secs())).to_string(),
119120
None => "0s".to_string(),
120121
};
121-
let mut info = Info::new().add_title(format!("TASK COMPLETED [{duration}]"));
122+
let mut info = Info::new().add_title(format!("TASK COMPLETED [in {duration}]"));
122123

123124
// Add file changes section inspired by the example format
124-
if !metrics.files_changed.is_empty() {
125+
if metrics.files_changed.is_empty() {
126+
info = info.add_key("[No Changes Produced]");
127+
} else {
125128
// First, calculate the maximum filename length for proper alignment
126129
let max_filename_len = metrics
127130
.files_changed

crates/forge_main/src/ui.rs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -856,10 +856,23 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
856856
}
857857

858858
async fn on_completion(&mut self, metrics: Metrics) -> anyhow::Result<()> {
859-
self.spinner.stop(None)?;
859+
self.spinner.start(Some("Loading Summary"))?;
860+
861+
let mut info = Info::default();
860862

861863
// Show summary
862-
self.writeln(Info::from(&metrics))?;
864+
info = info.extend(Info::from(&metrics));
865+
866+
// Fetch Usage
867+
info = info.extend(get_usage(&self.state));
868+
869+
if let Ok(Some(usage)) = self.api.user_usage().await {
870+
info = info.extend(Info::from(&usage));
871+
}
872+
873+
self.writeln(info)?;
874+
875+
self.spinner.stop(None)?;
863876

864877
let prompt_text = "Start a new conversation?";
865878
let should_start_new_chat = ForgeSelect::confirm(prompt_text)

0 commit comments

Comments
 (0)