Skip to content

Commit ec0f818

Browse files
chore: improve conversation switching message (#1791)
Co-authored-by: autofix-ci[bot] <114827586+autofix-ci[bot]@users.noreply.github.com>
1 parent fc3dedd commit ec0f818

4 files changed

Lines changed: 61 additions & 25 deletions

File tree

crates/forge_main/src/cli.rs

Lines changed: 41 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,10 @@ pub enum TopLevelCommand {
9696

9797
/// Show current configuration, active model, and environment status
9898
Info {
99+
/// Optional conversation ID to show info for a specific session
100+
#[arg(long, alias = "cid")]
101+
conversation_id: Option<String>,
102+
99103
/// Output in machine-readable format (porcelain)
100104
#[arg(long)]
101105
porcelain: bool,
@@ -679,7 +683,7 @@ mod tests {
679683
fn test_info_command_without_porcelain() {
680684
let fixture = Cli::parse_from(["forge", "info"]);
681685
let actual = match fixture.subcommands {
682-
Some(TopLevelCommand::Info { porcelain }) => porcelain,
686+
Some(TopLevelCommand::Info { porcelain, .. }) => porcelain,
683687
_ => true,
684688
};
685689
let expected = false;
@@ -690,13 +694,48 @@ mod tests {
690694
fn test_info_command_with_porcelain() {
691695
let fixture = Cli::parse_from(["forge", "info", "--porcelain"]);
692696
let actual = match fixture.subcommands {
693-
Some(TopLevelCommand::Info { porcelain }) => porcelain,
697+
Some(TopLevelCommand::Info { porcelain, .. }) => porcelain,
694698
_ => false,
695699
};
696700
let expected = true;
697701
assert_eq!(actual, expected);
698702
}
699703

704+
#[test]
705+
fn test_info_command_with_conversation_id() {
706+
let fixture = Cli::parse_from(["forge", "info", "--conversation-id", "abc123"]);
707+
let actual = match fixture.subcommands {
708+
Some(TopLevelCommand::Info { conversation_id, .. }) => conversation_id,
709+
_ => None,
710+
};
711+
let expected = Some("abc123".to_string());
712+
assert_eq!(actual, expected);
713+
}
714+
715+
#[test]
716+
fn test_info_command_with_cid_alias() {
717+
let fixture = Cli::parse_from(["forge", "info", "--cid", "xyz789"]);
718+
let actual = match fixture.subcommands {
719+
Some(TopLevelCommand::Info { conversation_id, .. }) => conversation_id,
720+
_ => None,
721+
};
722+
let expected = Some("xyz789".to_string());
723+
assert_eq!(actual, expected);
724+
}
725+
726+
#[test]
727+
fn test_info_command_with_conversation_id_and_porcelain() {
728+
let fixture = Cli::parse_from(["forge", "info", "--cid", "test123", "--porcelain"]);
729+
let (conversation_id, porcelain) = match fixture.subcommands {
730+
Some(TopLevelCommand::Info { conversation_id, porcelain }) => {
731+
(conversation_id, porcelain)
732+
}
733+
_ => (None, false),
734+
};
735+
assert_eq!(conversation_id, Some("test123".to_string()));
736+
assert_eq!(porcelain, true);
737+
}
738+
700739
#[test]
701740
fn test_list_agents_without_porcelain() {
702741
let fixture = Cli::parse_from(["forge", "list", "agents"]);

crates/forge_main/src/info.rs

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -208,15 +208,10 @@ impl fmt::Display for Info {
208208
Section::Items(key, value) => {
209209
if let Some(key) = key {
210210
if let Some(width) = width {
211-
writeln!(
212-
f,
213-
" {} {}",
214-
format!("{key:<width$}:").yellow().bold(),
215-
value
216-
)?;
211+
writeln!(f, " {} {}", format!("{key:<width$}:").cyan().bold(), value)?;
217212
} else {
218213
// No section width (items without a title)
219-
writeln!(f, " {}: {}", key.yellow().bold(), value)?;
214+
writeln!(f, " {}: {}", key.cyan().bold(), value)?;
220215
}
221216
} else {
222217
// Show value-only items

crates/forge_main/src/ui.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -359,11 +359,16 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
359359
self.writeln_title(TitleFormat::info("MCP reloaded"))?;
360360
}
361361
},
362-
TopLevelCommand::Info { porcelain } => {
362+
TopLevelCommand::Info { porcelain, conversation_id } => {
363363
// Make sure to init model
364364
self.on_new().await?;
365365

366-
self.on_info(porcelain, None).await?;
366+
let conversation_id = conversation_id
367+
.as_deref()
368+
.map(ConversationId::parse)
369+
.transpose()?;
370+
371+
self.on_info(porcelain, conversation_id).await?;
367372
return Ok(());
368373
}
369374
TopLevelCommand::Banner => {
@@ -463,8 +468,7 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
463468

464469
self.validate_session_exists(&conversation_id).await?;
465470

466-
self.on_info(session_group.porcelain, Some(conversation_id))
467-
.await?;
471+
self.on_show_conv_info(conversation_id).await?;
468472
}
469473
}
470474

@@ -1550,7 +1554,7 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
15501554
}
15511555
ChatResponse::TaskComplete => {
15521556
if let Some(conversation_id) = self.state.conversation_id {
1553-
self.on_completion(conversation_id).await?;
1557+
self.on_show_conv_info(conversation_id).await?;
15541558
}
15551559
}
15561560
}
@@ -1570,7 +1574,7 @@ impl<A: API + 'static, F: Fn() -> A> UI<A, F> {
15701574
Ok(())
15711575
}
15721576

1573-
async fn on_completion(&mut self, conversation_id: ConversationId) -> anyhow::Result<()> {
1577+
async fn on_show_conv_info(&mut self, conversation_id: ConversationId) -> anyhow::Result<()> {
15741578
if !should_show_completion_prompt() {
15751579
return Ok(());
15761580
}

shell-plugin/forge.plugin.zsh

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ function _forge_action_new() {
195195
function _forge_action_info() {
196196
echo
197197
if [[ -n "$FORGE_CONVERSATION_ID" ]]; then
198-
_forge_exec session info "$FORGE_CONVERSATION_ID"
198+
_forge_exec info --cid "$FORGE_CONVERSATION_ID"
199199
else
200200
_forge_exec info
201201
fi
@@ -256,18 +256,16 @@ function _forge_action_conversation() {
256256

257257
# Set the selected conversation as active (in parent shell)
258258
FORGE_CONVERSATION_ID="$conversation_id"
259-
260-
# Show conversation info
259+
# Show conversation content
261260
echo
262-
_forge_exec session info "$conversation_id"
263-
261+
_forge_exec session show "$conversation_id"
262+
263+
# Show conversation info
264+
_forge_exec session info "$conversation_id"
265+
264266
# Print log about conversation switching
265-
echo
266267
echo "\033[36m⏺\033[0m \033[90m[$(date '+%H:%M:%S')] Switched to conversation \033[1m${conversation_id}\033[0m"
267-
268-
# Show conversation content
269-
echo
270-
_forge_exec session show "$conversation_id"
268+
271269
fi
272270
else
273271
echo "\033[31m✗\033[0m No conversations found"

0 commit comments

Comments
 (0)