Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,294 changes: 0 additions & 1,294 deletions crates/pu-cli/src/output.rs

This file was deleted.

169 changes: 169 additions & 0 deletions crates/pu-cli/src/output/agents.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
use owo_colors::OwoColorize;
use pu_core::protocol::AgentStatusReport;
use pu_core::types::{AgentStatus, WorktreeEntry};

use super::formatters::{status_colored, status_colored_with_suspended, trigger_progress};

pub(crate) fn print_spawn_result(
worktree_id: &Option<String>,
agent_id: &str,
status: AgentStatus,
) {
println!(
"Spawned agent {} ({})",
agent_id.bold(),
status_colored(status, None)
);
if let Some(wt) = worktree_id {
println!(" Worktree: {wt}");
}
}

pub(crate) fn print_status_report(worktrees: &[WorktreeEntry], agents: &[AgentStatusReport]) {
if worktrees.is_empty() && agents.is_empty() {
println!("No active agents");
return;
}
if !agents.is_empty() {
println!(
"{:<14} {:<16} {}",
"ID".bold(),
"NAME".bold(),
"STATUS".bold()
);
for a in agents {
println!(
"{:<14} {:<16} {}{}",
a.id.dimmed(),
a.name,
status_colored_with_suspended(a.status, a.exit_code, a.suspended),
trigger_progress(a)
);
}
}
for wt in worktrees {
println!(
"\n{} {} ({}) — {:?}",
"Worktree".bold(),
wt.id.dimmed(),
wt.branch,
wt.status,
);
if !wt.agents.is_empty() {
println!(
" {:<14} {:<16} {}",
"ID".bold(),
"NAME".bold(),
"STATUS".bold()
);
for a in wt.agents.values() {
println!(
" {:<14} {:<16} {}",
a.id.dimmed(),
a.name,
status_colored_with_suspended(a.status, a.exit_code, a.suspended),
);
}
}
}
}

pub(crate) fn print_agent_status(a: &AgentStatusReport) {
println!(
"{} {} {}{}",
a.id.dimmed(),
a.name.bold(),
status_colored_with_suspended(a.status, a.exit_code, a.suspended),
trigger_progress(a)
);
if let Some(pid) = a.pid {
println!(" PID: {pid}");
}
if let Some(code) = a.exit_code {
println!(" Exit: {code}");
}
if let Some(idle) = a.idle_seconds {
println!(" Idle: {idle}s");
}
if let Some(ref wt) = a.worktree_id {
println!(" Worktree: {wt}");
}
if let (Some(state), Some(idx), Some(total)) =
(a.trigger_state, a.trigger_seq_index, a.trigger_total)
{
println!(" Trigger: {idx}/{total} ({state:?})");
}
}

pub(crate) fn print_kill_result(killed: &[String]) {
println!("Killed {} agent(s)", killed.len());
}

pub(crate) fn print_suspend_result(suspended: &[String]) {
if suspended.is_empty() {
println!("No agents to bench");
} else {
println!("Benched {} agent(s)", suspended.len());
for id in suspended {
println!(" {}", id.dimmed());
}
}
}

pub(crate) fn print_resume_result(agent_id: &str, status: AgentStatus) {
println!(
"Back in play: {} ({})",
agent_id.bold(),
status_colored(status, None)
);
}

pub(crate) fn print_rename_result(agent_id: &str, name: &str) {
println!("Renamed agent {} to {}", agent_id.bold(), name.green());
}

pub(crate) fn print_assign_trigger_result(agent_id: &str, trigger_name: &str, sequence_len: u32) {
println!(
"Assigned trigger {} to agent {} ({} steps)",
trigger_name.green(),
agent_id.bold(),
sequence_len
);
}

pub(crate) fn print_logs_result(agent_id: &str, data: &str) {
println!("{}", format!("--- Logs for {agent_id} ---").dimmed());
print!("{data}");
}

pub(crate) fn print_create_worktree_result(worktree_id: &str) {
println!("Created worktree {}", worktree_id.bold());
}

pub(crate) fn print_delete_worktree_result(
worktree_id: &str,
killed_agents: &[String],
branch_deleted: bool,
remote_deleted: bool,
) {
println!("Deleted worktree {}", worktree_id.bold());
if !killed_agents.is_empty() {
println!(" Killed {} agent(s)", killed_agents.len());
}
println!(
" Branch deleted: {}",
if branch_deleted {
"yes".green().to_string()
} else {
"no".dimmed().to_string()
}
);
println!(
" Remote deleted: {}",
if remote_deleted {
"yes".green().to_string()
} else {
"no".dimmed().to_string()
}
);
}
150 changes: 150 additions & 0 deletions crates/pu-cli/src/output/definitions.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
use owo_colors::OwoColorize;
use pu_core::protocol::{AgentDefInfo, SwarmDefInfo, SwarmRosterEntryPayload, TemplateInfo};

pub(crate) fn print_template_list(templates: &[TemplateInfo]) {
if templates.is_empty() {
println!("No templates");
return;
}
println!(
"{:<20} {:<12} {:<10} {}",
"NAME".bold(),
"AGENT".bold(),
"SOURCE".bold(),
"VARIABLES".bold()
);
for t in templates {
println!(
"{:<20} {:<12} {:<10} {}",
t.name,
t.agent,
t.source,
t.variables.join(", ")
);
}
}

pub(crate) fn print_template_detail(
name: &str,
description: &str,
agent: &str,
body: &str,
source: &str,
variables: &[String],
command: &Option<String>,
) {
println!("{} ({})", name.bold(), source.dimmed());
if !description.is_empty() {
println!(" {description}");
}
println!(" Agent: {agent}");
if let Some(cmd) = command {
println!(" Command: {cmd}");
}
if !variables.is_empty() {
println!(" Variables: {}", variables.join(", "));
}
println!("---");
print!("{body}");
}

#[allow(clippy::too_many_arguments)]
pub(crate) fn print_agent_def_detail(
name: &str,
agent_type: &str,
template: &Option<String>,
inline_prompt: &Option<String>,
tags: &[String],
scope: &str,
available_in_command_dialog: bool,
icon: &Option<String>,
command: &Option<String>,
) {
println!("{} ({})", name.bold(), scope.dimmed());
println!(" Type: {agent_type}");
if let Some(cmd) = command {
println!(" Command: {cmd}");
}
if let Some(tpl) = template {
println!(" Template: {tpl}");
}
if let Some(prompt) = inline_prompt {
println!(" Inline prompt:");
for line in prompt.lines() {
println!(" {line}");
}
}
if !tags.is_empty() {
println!(" Tags: {}", tags.join(", "));
}
if let Some(ic) = icon {
println!(" Icon: {ic}");
}
println!(" Command dialog: {available_in_command_dialog}");
}

pub(crate) fn print_agent_def_list(agent_defs: &[AgentDefInfo]) {
if agent_defs.is_empty() {
println!("No agent definitions");
return;
}
println!(
"{:<20} {:<12} {:<10}",
"NAME".bold(),
"TYPE".bold(),
"SCOPE".bold()
);
for d in agent_defs {
println!("{:<20} {:<12} {:<10}", d.name, d.agent_type, d.scope);
}
}

pub(crate) fn print_swarm_def_detail(
name: &str,
worktree_count: u32,
worktree_template: &str,
roster: &[SwarmRosterEntryPayload],
include_terminal: bool,
scope: &str,
) {
println!("{} ({})", name.bold(), scope.dimmed());
println!(" Worktrees: {worktree_count}");
if !worktree_template.is_empty() {
println!(" Template: {worktree_template}");
}
println!(" Terminal: {include_terminal}");
if !roster.is_empty() {
println!(" Roster:");
for r in roster {
println!(" {} ({}) x{}", r.agent_def, r.role, r.quantity);
}
}
}

pub(crate) fn print_swarm_def_list(swarm_defs: &[SwarmDefInfo]) {
if swarm_defs.is_empty() {
println!("No swarm definitions");
return;
}
println!(
"{:<20} {:<10} {:<10} {}",
"NAME".bold(),
"WORKTREES".bold(),
"SCOPE".bold(),
"ROSTER".bold()
);
for d in swarm_defs {
let roster_summary: Vec<String> = d
.roster
.iter()
.map(|r| format!("{}x{}", r.agent_def, r.quantity))
.collect();
println!(
"{:<20} {:<10} {:<10} {}",
d.name,
d.worktree_count,
d.scope,
roster_summary.join(", ")
);
}
}
Loading
Loading