diff --git a/lib/crates/fabro-workflows/src/cli/logs.rs b/lib/crates/fabro-workflows/src/cli/logs.rs index 084209d06..3f6bd6324 100644 --- a/lib/crates/fabro-workflows/src/cli/logs.rs +++ b/lib/crates/fabro-workflows/src/cli/logs.rs @@ -194,6 +194,22 @@ fn follow_logs( // ── Pretty formatter ────────────────────────────────────────────────── +/// Render markdown text with indentation, wrapping to terminal width. +fn render_indented_markdown( + styles: &fabro_util::terminal::Styles, + text: &str, + indent: &str, +) -> String { + let term_width = fabro_util::terminal::Styles::terminal_width(); + let wrap_width = term_width.saturating_sub(indent.len()); + let rendered = styles.render_markdown_width(text, wrap_width); + rendered + .lines() + .map(|l| format!("{indent}{l}")) + .collect::>() + .join("\n") +} + pub fn format_event_pretty(line: &str, styles: &fabro_util::terminal::Styles) -> Option { let envelope: serde_json::Value = serde_json::from_str(line).ok()?; let event = envelope.get("event")?.as_str()?; @@ -203,13 +219,20 @@ pub fn format_event_pretty(line: &str, styles: &fabro_util::terminal::Styles) -> "WorkflowRunStarted" => { let name = str_field(&envelope, "workflow_name").unwrap_or("?"); let run_id = str_field(&envelope, "run_id").unwrap_or("?"); - Some(format!( + let header = format!( "{} {} {} {}", styles.dim.apply_to(&ts), styles.bold_cyan.apply_to("\u{25b6}"), styles.bold.apply_to(name), styles.dim.apply_to(run_id), - )) + ); + match str_field(&envelope, "goal") { + Some(goal) if !goal.is_empty() => { + let body = render_indented_markdown(styles, goal, " "); + Some(format!("{header}\n{body}\n")) + } + _ => Some(header), + } } "WorkflowRunCompleted" => { @@ -349,15 +372,7 @@ pub fn format_event_pretty(line: &str, styles: &fabro_util::terminal::Styles) -> styles.dim.apply_to(model), styles.dim.apply_to("]"), ); - let indent = " "; - let term_width = fabro_util::terminal::Styles::terminal_width(); - let wrap_width = term_width.saturating_sub(indent.len()); - let rendered = styles.render_markdown_width(text, wrap_width); - let body: String = rendered - .lines() - .map(|l| format!("{indent}{l}")) - .collect::>() - .join("\n"); + let body = render_indented_markdown(styles, text, " "); Some(format!("{header}\n{body}\n")) } @@ -816,6 +831,27 @@ mod tests { assert!(result.contains("abc123"), "got: {result}"); } + #[test] + fn pretty_workflow_run_started_with_goal() { + let styles = no_color_styles(); + let line = r#"{"ts":"2026-01-01T14:23:01Z","run_id":"abc123","event":"WorkflowRunStarted","workflow_name":"smoke","goal":"Fix the bug"}"#; + let result = format_event_pretty(line, &styles).unwrap(); + assert!(result.contains("smoke"), "got: {result}"); + assert!(result.contains("abc123"), "got: {result}"); + assert!(result.contains("Fix the bug"), "got: {result}"); + // Should be multi-line (header + body) + assert!(result.contains('\n'), "got: {result}"); + } + + #[test] + fn pretty_workflow_run_started_without_goal_no_extra_lines() { + let styles = no_color_styles(); + let line = r#"{"ts":"2026-01-01T14:23:01Z","run_id":"abc123","event":"WorkflowRunStarted","workflow_name":"smoke"}"#; + let result = format_event_pretty(line, &styles).unwrap(); + // Without goal, should be a single line (no newlines) + assert!(!result.contains('\n'), "got: {result}"); + } + #[test] fn pretty_workflow_run_completed() { let styles = no_color_styles(); diff --git a/lib/crates/fabro-workflows/src/engine.rs b/lib/crates/fabro-workflows/src/engine.rs index 47e7da216..d9a71b8f6 100644 --- a/lib/crates/fabro-workflows/src/engine.rs +++ b/lib/crates/fabro-workflows/src/engine.rs @@ -1229,6 +1229,7 @@ impl WorkflowRunEngine { } else { None }, + goal: (!graph.goal().is_empty()).then(|| graph.goal().to_string()), }); // Resolve work_dir from config for hooks diff --git a/lib/crates/fabro-workflows/src/event.rs b/lib/crates/fabro-workflows/src/event.rs index 449216cb0..85a579792 100644 --- a/lib/crates/fabro-workflows/src/event.rs +++ b/lib/crates/fabro-workflows/src/event.rs @@ -17,6 +17,8 @@ pub enum WorkflowRunEvent { run_branch: Option, #[serde(default, skip_serializing_if = "Option::is_none")] worktree_dir: Option, + #[serde(default, skip_serializing_if = "Option::is_none")] + goal: Option, }, WorkflowRunCompleted { duration_ms: u64, @@ -1091,6 +1093,7 @@ mod tests { base_sha: None, run_branch: None, worktree_dir: None, + goal: None, }); let events = received.lock().unwrap(); assert_eq!(events.len(), 1); @@ -1588,6 +1591,7 @@ mod tests { base_sha: None, run_branch: None, worktree_dir: None, + goal: None, }); assert!(emitter.last_event_at() > 0); } @@ -1757,6 +1761,7 @@ mod tests { base_sha: None, run_branch: None, worktree_dir: None, + goal: None, }; let (name, fields) = flatten_event(&event); assert_eq!(name, "WorkflowRunStarted"); @@ -2333,6 +2338,52 @@ mod tests { assert!(!fields.contains_key("index")); } + #[test] + fn workflow_run_started_with_goal_round_trip() { + let event = WorkflowRunEvent::WorkflowRunStarted { + name: "my_workflow".to_string(), + run_id: "r42".to_string(), + base_sha: None, + run_branch: None, + worktree_dir: None, + goal: Some("Fix the bug".to_string()), + }; + let json = serde_json::to_string(&event).unwrap(); + assert!(json.contains("\"goal\":\"Fix the bug\"")); + let deserialized: WorkflowRunEvent = serde_json::from_str(&json).unwrap(); + assert!( + matches!(deserialized, WorkflowRunEvent::WorkflowRunStarted { goal: Some(g), .. } if g == "Fix the bug") + ); + } + + #[test] + fn workflow_run_started_without_goal_backward_compat() { + // Old JSONL without `goal` field should deserialize to `goal: None` + let json = r#"{"WorkflowRunStarted":{"name":"old_wf","run_id":"r1"}}"#; + let deserialized: WorkflowRunEvent = serde_json::from_str(json).unwrap(); + assert!(matches!( + deserialized, + WorkflowRunEvent::WorkflowRunStarted { goal: None, .. } + )); + } + + #[test] + fn workflow_run_started_goal_none_omitted_from_json() { + let event = WorkflowRunEvent::WorkflowRunStarted { + name: "wf".to_string(), + run_id: "r1".to_string(), + base_sha: None, + run_branch: None, + worktree_dir: None, + goal: None, + }; + let json = serde_json::to_string(&event).unwrap(); + assert!( + !json.contains("goal"), + "goal: None should be skipped, got: {json}" + ); + } + #[test] fn retro_started_event_serialization() { let event = WorkflowRunEvent::RetroStarted;