MCPcopy Create free account
hub / github.com/aws/amazon-q-developer-cli / format_rich_notification

Function format_rich_notification

crates/chat-cli/src/cli/chat/mod.rs:476–534  ·  view source on GitHub ↗
(executions: &[AgentExecution])

Source from the content-addressed store, hash-verified

474}
475
476fn format_rich_notification(executions: &[AgentExecution]) -> String {
477 let count = executions.len();
478 let header = if count == 1 {
479 "1 Background Task Completed".to_string()
480 } else {
481 format!("{} Background Tasks Completed", count)
482 };
483
484 // Plain text notification - will be colored by highlight_prompt
485 let mut notification = format!("{}\n\n", header);
486
487 for (i, execution) in executions.iter().enumerate() {
488 let status_icon = match execution.status {
489 tools::delegate::AgentStatus::Completed => "✓ SUCCESS",
490 tools::delegate::AgentStatus::Failed => "✗ FAILED",
491 tools::delegate::AgentStatus::Running => "⏳ RUNNING", // shouldn't happen but just in case
492 };
493
494 let time_ago = if let Some(completed_at) = execution.completed_at {
495 let duration = chrono::Utc::now().signed_duration_since(completed_at);
496 if duration.num_minutes() < 1 {
497 "Completed just now".to_string()
498 } else if duration.num_minutes() < 60 {
499 format!("Completed {} min ago", duration.num_minutes())
500 } else if duration.num_hours() < 24 {
501 format!("Completed {} hr ago", duration.num_hours())
502 } else {
503 format!("Completed {} days ago", duration.num_days())
504 }
505 } else {
506 "unknown".to_string()
507 };
508
509 // Shorten CWD path - replace home directory with ~
510 let shortened_cwd = if let Ok(home) = std::env::var("HOME") {
511 execution.cwd.replace(&home, "~")
512 } else {
513 execution.cwd.clone()
514 };
515
516 let summary = execution.summary.as_deref().unwrap_or("No summary available");
517
518 notification.push_str(&format!(
519 "[{}] {} · {} · {} · {}\n\nTask: {}\n\n{}\n\n",
520 i + 1,
521 execution.agent,
522 shortened_cwd,
523 status_icon,
524 time_ago,
525 execution.task,
526 summary
527 ));
528 }
529
530 // Add footer with instructions
531 notification.push_str("To read the full details of any task, ask the delegate tool.\n");
532
533 notification

Callers 1

Calls 3

to_stringMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected