Add Needs-you queue and goal view with acceptance checks
- needs table: human steps, permission requests and agent questions wait
for an answer written to the database; a/c/d, y/Y/n, r keys in the TUI
- goal view (g): task graph, critical path, decisions, acceptance checks;
e edit goal, + add check, R run all checks on main
- checks.rs: acceptance checks on a branch or on main in a clean worktree
- runner: wait for --after dependencies, one session in merge at a time,
all checks again on main after each merge
- orch goal / check / checks commands, ORCH_DB and {{repo}} for machine steps
- example machines merge with git merge --ff-only
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
5b659fa8ba
commit
7bf0986640
16 files changed
+2551
-105
No files matched your search
+294
@@ -0,0 +1,294 @@
|
||||
//! 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) {
|
||||
let area = f.area();
|
||||
f.render_widget(
|
||||
Block::new().style(Style::new().bg(theme::BG).fg(theme::TEXT)),
|
||||
area,
|
||||
);
|
||||
let [head, goal, body, keys] = Layout::vertical([
|
||||
Constraint::Length(1),
|
||||
Constraint::Length(4),
|
||||
Constraint::Fill(1),
|
||||
Constraint::Length(1),
|
||||
])
|
||||
.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(56)]).areas(body);
|
||||
left_box(f, left, g);
|
||||
acceptance_box(f, right, g, checks_running);
|
||||
f.render_widget(key_bar(), 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) {
|
||||
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;
|
||||
let lines: Vec<Line> = g
|
||||
.decisions
|
||||
.iter()
|
||||
.take(di.height as usize)
|
||||
.map(|d| {
|
||||
let text_style = if d.vetoed {
|
||||
fg(theme::DIM).add_modifier(Modifier::CROSSED_OUT)
|
||||
} else {
|
||||
Style::new()
|
||||
};
|
||||
Line::from(vec![
|
||||
Span::styled(format!(" {:<4}", d.session), fg(theme::RUN)),
|
||||
Span::styled(fit(&d.text, w.saturating_sub(22)), text_style),
|
||||
Span::styled(format!(" {:<14}", d.whence), fg(theme::DIM)),
|
||||
])
|
||||
})
|
||||
.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);
|
||||
}
|
||||
|
||||
fn key_bar() -> Line<'static> {
|
||||
let mut v = vec![Span::raw(" ")];
|
||||
for (k, what) in [
|
||||
("esc", "back"),
|
||||
("e", "edit goal"),
|
||||
("+", "add check"),
|
||||
("R", "run all checks"),
|
||||
] {
|
||||
v.push(Span::styled(
|
||||
format!(" {k} "),
|
||||
Style::new().fg(theme::BG).bg(theme::DIM),
|
||||
));
|
||||
v.push(Span::styled(format!(" {what} "), fg(theme::DIM)));
|
||||
}
|
||||
Line::from(v)
|
||||
}
|
||||
Reference in new issue
Block a user