- Use the terminal's own colors and background; the key bar and the Needs-you panel wrap, fixed-width panels shrink on narrow terminals. - Sessions run on threads of the TUI (tui/host.rs), capped by the profile's `workers`; quitting asks for `yes` and suspends them. New `suspend` command keeps the state so a session can be resumed. - `N` opens a new-session form: machine, name, --after, a named branch or worktree (place.rs; never deleted by orch), and a "keep for a PR" option. - `u` resumes suspended sessions and ones whose process died. - `A` allows identical permission requests across sessions, `P` saves an allow rule to the profile with toml_edit (comments kept). - Fix clippy lint in report.rs so tests/all.sh passes; add GLOSSARY.md. Includes the already staged `orch init` work (init.rs, example profile). Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
299 lines
9.6 KiB
Rust
299 lines
9.6 KiB
Rust
//! Screen 3: goal view (ORCHESTRATOR.md 7.3, `Goal.dc.html`).
|
||
|
||
use super::overview::Header;
|
||
use super::theme::{self, bold, fg, inverted};
|
||
use crate::goal::{CheckState, GoalView, TaskBox};
|
||
use crate::view::{Status, hms};
|
||
use ratatui::Frame;
|
||
use ratatui::layout::{Constraint, Layout, Rect};
|
||
use ratatui::style::{Color, Modifier, Style};
|
||
use ratatui::text::{Line, Span};
|
||
use ratatui::widgets::{Block, Paragraph};
|
||
use unicode_width::UnicodeWidthStr;
|
||
|
||
const BOX_W: u16 = 26;
|
||
const GAP_W: u16 = 5;
|
||
const BOX_H: u16 = 5;
|
||
|
||
pub fn draw(f: &mut Frame, g: &GoalView, h: &Header, checks_running: bool, dec_sel: usize) {
|
||
let area = f.area();
|
||
let key_lines = theme::key_lines(&KEYS, area.width);
|
||
let [head, goal, body, keys] = Layout::vertical([
|
||
Constraint::Length(1),
|
||
Constraint::Length(4),
|
||
Constraint::Fill(1),
|
||
Constraint::Length(key_lines.len() as u16),
|
||
])
|
||
.areas(area);
|
||
f.render_widget(header(h, head.width as usize), head);
|
||
goal_box(f, goal, g);
|
||
let [left, right] = Layout::horizontal([
|
||
Constraint::Fill(1),
|
||
Constraint::Length(theme::capped(body, 56, 45)),
|
||
])
|
||
.areas(body);
|
||
left_box(f, left, g, dec_sel);
|
||
acceptance_box(f, right, g, checks_running);
|
||
f.render_widget(Paragraph::new(key_lines), keys);
|
||
}
|
||
|
||
fn header(h: &Header, width: usize) -> Line<'static> {
|
||
let clock = hms(h.now_ms);
|
||
let used = " hx·orch ".width() + " ‹ sessions / goal".width() + clock.width();
|
||
Line::from(vec![
|
||
Span::styled(" hx·orch ", inverted(theme::RUN)),
|
||
Span::styled(" ‹ sessions / ", fg(theme::DIM)),
|
||
Span::styled("goal", bold(theme::TEXT)),
|
||
Span::raw(" ".repeat(width.saturating_sub(used))),
|
||
Span::raw(clock),
|
||
])
|
||
}
|
||
|
||
fn fit(s: &str, w: usize) -> String {
|
||
if s.width() <= w {
|
||
return s.to_string();
|
||
}
|
||
let mut out = String::new();
|
||
for c in s.chars() {
|
||
if out.width() + 1 >= w {
|
||
break;
|
||
}
|
||
out.push(c);
|
||
}
|
||
out.push('…');
|
||
out
|
||
}
|
||
|
||
fn titled<'a>(title: Vec<Span<'a>>, border: Color) -> Block<'a> {
|
||
let mut t = vec![Span::raw(" ")];
|
||
t.extend(title);
|
||
t.push(Span::raw(" "));
|
||
Block::bordered()
|
||
.border_style(fg(border))
|
||
.title(Line::from(t))
|
||
}
|
||
|
||
fn goal_box(f: &mut Frame, area: Rect, g: &GoalView) {
|
||
let b = Block::bordered().border_style(fg(theme::BORDER));
|
||
let inner = b.inner(area);
|
||
f.render_widget(b, area);
|
||
let w = inner.width as usize;
|
||
f.render_widget(
|
||
Paragraph::new(vec![
|
||
Line::from(Span::styled(
|
||
format!(" {}", fit(&g.goal, w - 1)),
|
||
bold(theme::TEXT),
|
||
)),
|
||
Line::from(Span::styled(
|
||
format!(" {}", fit(&g.done_when, w - 1)),
|
||
fg(theme::DIM),
|
||
)),
|
||
]),
|
||
inner,
|
||
);
|
||
}
|
||
|
||
fn status_color(s: Status) -> Color {
|
||
match s {
|
||
Status::Done => theme::OK,
|
||
Status::Fix | Status::Fail => theme::ERR,
|
||
Status::Wait => theme::WAIT,
|
||
Status::Run => theme::RUN,
|
||
Status::Blocked => theme::AGENT,
|
||
}
|
||
}
|
||
|
||
fn task_box(f: &mut Frame, area: Rect, t: &TaskBox) {
|
||
let border = if t.status == Status::Done {
|
||
theme::BORDER
|
||
} else {
|
||
status_color(t.status)
|
||
};
|
||
let b = Block::bordered().border_style(fg(border));
|
||
let inner = b.inner(area);
|
||
f.render_widget(b, area);
|
||
let w = inner.width as usize;
|
||
let after = if t.after.is_empty() {
|
||
"after: —".to_string()
|
||
} else {
|
||
format!("after: {}", t.after.join(", "))
|
||
};
|
||
f.render_widget(
|
||
Paragraph::new(vec![
|
||
Line::from(vec![
|
||
Span::styled(format!("{} ", t.id), fg(theme::DIM)),
|
||
Span::styled(fit(&t.name, w.saturating_sub(4)), bold(theme::TEXT)),
|
||
]),
|
||
Line::from(Span::styled(
|
||
fit(&format!("{} · {}", t.status.label(), t.detail), w),
|
||
bold(status_color(t.status)),
|
||
)),
|
||
Line::from(Span::styled(fit(&after, w), fg(theme::DIM))),
|
||
]),
|
||
inner,
|
||
);
|
||
}
|
||
|
||
fn left_box(f: &mut Frame, area: Rect, g: &GoalView, dec_sel: usize) {
|
||
let title = vec![
|
||
Span::styled("Task graph", bold(theme::TEXT)),
|
||
Span::styled(" left to right = dependency order", fg(theme::DIM)),
|
||
];
|
||
let b = titled(title, theme::BORDER);
|
||
let inner = b.inner(area);
|
||
f.render_widget(b, area);
|
||
let tallest = g.columns.iter().map(|c| c.tasks.len()).max().unwrap_or(0) as u16;
|
||
let graph_h = (1 + tallest * (BOX_H + 1)).max(3);
|
||
let [graph, crit, decisions] = Layout::vertical([
|
||
Constraint::Length(graph_h.min(inner.height.saturating_sub(8))),
|
||
Constraint::Length(3),
|
||
Constraint::Fill(1),
|
||
])
|
||
.areas(inner);
|
||
|
||
let step = BOX_W + GAP_W;
|
||
for (c, col) in g.columns.iter().enumerate() {
|
||
let x = graph.x + 1 + c as u16 * step;
|
||
if x + BOX_W > graph.right() {
|
||
break; // does not fit on this terminal
|
||
}
|
||
f.render_widget(
|
||
Span::styled(col.label.clone(), fg(theme::DIM)),
|
||
Rect::new(x, graph.y, BOX_W, 1),
|
||
);
|
||
for (i, t) in col.tasks.iter().enumerate() {
|
||
let y = graph.y + 1 + i as u16 * (BOX_H + 1);
|
||
if y + BOX_H > graph.bottom() {
|
||
break;
|
||
}
|
||
task_box(f, Rect::new(x, y, BOX_W, BOX_H), t);
|
||
if c + 1 < g.columns.len() {
|
||
f.render_widget(
|
||
Span::styled("──▶", fg(theme::SEP)),
|
||
Rect::new(x + BOX_W + 1, y + 2, 3, 1),
|
||
);
|
||
}
|
||
}
|
||
}
|
||
|
||
let crit_line = if g.critical.is_empty() {
|
||
Line::from(Span::styled(
|
||
" critical path nothing left to do",
|
||
fg(theme::DIM),
|
||
))
|
||
} else {
|
||
Line::from(vec![
|
||
Span::styled(" critical path ", bold(theme::WAIT)),
|
||
Span::raw(g.critical.join(" → ")),
|
||
])
|
||
};
|
||
let sep = Block::new()
|
||
.borders(ratatui::widgets::Borders::TOP)
|
||
.border_style(fg(theme::BORDER));
|
||
f.render_widget(Paragraph::new(crit_line).block(sep), crit);
|
||
|
||
let db = titled(
|
||
vec![Span::styled("Decisions agents made", bold(theme::TEXT))],
|
||
theme::BORDER,
|
||
);
|
||
let di = db.inner(decisions);
|
||
f.render_widget(db, decisions);
|
||
let w = di.width as usize;
|
||
// scroll so the selected decision stays in view
|
||
let skip = dec_sel.saturating_sub((di.height as usize).saturating_sub(1));
|
||
let lines: Vec<Line> = g
|
||
.decisions
|
||
.iter()
|
||
.enumerate()
|
||
.skip(skip)
|
||
.take(di.height as usize)
|
||
.map(|(i, d)| {
|
||
let text_style = if d.vetoed {
|
||
fg(theme::DIM).add_modifier(Modifier::CROSSED_OUT)
|
||
} else {
|
||
Style::new()
|
||
};
|
||
let cursor = if i == dec_sel {
|
||
Span::styled("▶", fg(theme::RUN))
|
||
} else {
|
||
Span::raw(" ")
|
||
};
|
||
let tag = if d.vetoed { " vetoed" } else { "" };
|
||
Line::from(vec![
|
||
cursor,
|
||
Span::styled(format!("{:<4}", d.session), fg(theme::RUN)),
|
||
Span::styled(fit(&d.text, w.saturating_sub(30)), text_style),
|
||
Span::styled(format!(" {:<14}", d.whence), fg(theme::DIM)),
|
||
Span::styled(tag, fg(theme::ERR)),
|
||
])
|
||
})
|
||
.collect();
|
||
if lines.is_empty() {
|
||
f.render_widget(Span::styled(" none reported yet", fg(theme::DIM)), di);
|
||
} else {
|
||
f.render_widget(Paragraph::new(lines), di);
|
||
}
|
||
}
|
||
|
||
fn acceptance_box(f: &mut Frame, area: Rect, g: &GoalView, running: bool) {
|
||
let mut title = vec![
|
||
Span::styled("Acceptance ", bold(theme::TEXT)),
|
||
Span::styled(g.green.to_string(), fg(theme::OK)),
|
||
Span::styled(format!("/{}", g.checks.len()), fg(theme::DIM)),
|
||
];
|
||
if running {
|
||
title.push(Span::styled(" running…", fg(theme::WAIT)));
|
||
}
|
||
let b = titled(title, theme::BORDER);
|
||
let inner = b.inner(area);
|
||
f.render_widget(b, area);
|
||
let w = inner.width.saturating_sub(2) as usize;
|
||
let total = g.checks.len();
|
||
let on = (g.green * w).checked_div(total).unwrap_or(0);
|
||
let mut lines = vec![
|
||
Line::from(vec![
|
||
Span::raw(" "),
|
||
Span::styled("█".repeat(on), fg(theme::OK)),
|
||
Span::styled("█".repeat(w - on), fg(theme::BORDER)),
|
||
]),
|
||
Line::raw(""),
|
||
];
|
||
if g.checks.is_empty() {
|
||
lines.push(Line::from(Span::styled(
|
||
" no checks yet · press +",
|
||
fg(theme::DIM),
|
||
)));
|
||
}
|
||
for c in &g.checks {
|
||
let (mark, style, name_style) = match c.state {
|
||
CheckState::Pass => ("✓", fg(theme::OK), Style::new()),
|
||
CheckState::Fail => (
|
||
"✗",
|
||
fg(theme::ERR),
|
||
Style::new().add_modifier(Modifier::BOLD),
|
||
),
|
||
CheckState::Unknown => ("·", fg(theme::TODO), fg(theme::DIM)),
|
||
};
|
||
let owner_w = 4; // `s12`, `ci`, `-`: right-aligned in a fixed column
|
||
let name_w = w.saturating_sub(owner_w + 4);
|
||
lines.push(Line::from(vec![
|
||
Span::raw(" "),
|
||
Span::styled(mark, style),
|
||
Span::raw(" "),
|
||
Span::styled(format!("{:<name_w$}", fit(&c.name, name_w)), name_style),
|
||
Span::raw(" "),
|
||
Span::styled(format!("{:>owner_w$}", c.owner), fg(theme::DIM)),
|
||
]));
|
||
}
|
||
f.render_widget(Paragraph::new(lines), inner);
|
||
}
|
||
|
||
const KEYS: [(&str, &str); 6] = [
|
||
("esc", "back"),
|
||
("e", "edit goal"),
|
||
("+", "add check"),
|
||
("R", "run all checks"),
|
||
("j/k", "select decision"),
|
||
("v", "veto decision"),
|
||
];
|