xonecas.io
8447
Co

conveyor / commit c8081ea

Starter kit: Widgets dropdown, board and ticket

Made with the builder on a fresh install: the title bar's Widgets
dropdown lists placeable widgets with their descriptions, board is a
kanban of the project's tickets (drag to move, quick-add), and ticket
edits one and acts by state, showing a review's branch diff stat.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-09 c8081eaa42c8713e78f9f40c9a0553790acbda98 parent effc09c

9 files changed

DESIGN.md+1−0
@@ -209,6 +209,7 @@ Ctrl+click ─► conveyord: widgets ticket (kind, instance chain, tree, shared,
209209 - **Hidden work survives reloads.** Instances exist once rendered; `cx.keep_running()` from `update` makes the app bring one back after a reload or restart even when nothing shows it.
210210 - **A broken widget can't take the app down** (catching what it can: `new`, `view`, `update`, `event` and `on` handlers). A panic turns that one instance into a red card, Ctrl+clickable. If `root` or `status` stops, or the user Ctrl+clicks the inspector's Safe mode button, or starts with `--safe`, the core runs alone: no widget code, the builds on trial with Keep and Discard, and Leave. The shared value `safe_mode = off` stops offering it, for those who'd rather not.
211211 - **Widgets run with every permission the user has.** They are native code in the app, on the host: any file, any program, the network. The agent that writes them is sandboxed in a VM, the code it writes is not. That's deliberate for now, and may be a feature (a widget can drive the whole machine). Revisit before anyone runs someone else's library.
212+- **A starter kit ships in the template**, every widget made with the builder: the title bar's Widgets dropdown (each placeable widget with its description), `board` (kanban by state, drag to move, quick-add), `ticket` (edit, conversation, actions by state, a review's `git diff --stat`), `editor`, `library`, a canvas per project and a taskbar of projects. A first run is an empty canvas: pick from the dropdown, or Ctrl+click to make your own.
212213 - **`api.rs` is conveyor's contract**, copied into the library on every start along with `gen.rs`, `CLAUDE.md` and the preview. The preview is the app's own host (`api::Live`) with sample data, so the agent checks exactly what the app runs.
213214 - The app restarts (on a conveyor change) with `exec` on the path it read at launch, and conveyord copies itself into VMs from `/proc/self/exe`: after cargo replaces a binary, `current_exe()` names the deleted file.
214215 - The base image carries the pinned toolchain and a warm `~/.cache/conveyor-target`, so the agent's first preview build is incremental.
templates/library/widgets/board.rs+144−0
@@ -0,0 +1,144 @@
1+//! A kanban board of the tickets of the project whose desktop this is: a column per state with
2+//! counts, and cards with #id, title and time in that state. Drag a card to move it (never into
3+//! or out of running), type at the top of draft to write a new one, and click a card to open it.
4+use super::{api::*, canvas::{self, Canvas}};
5+use rune::{Drag, El, Phase, ScrollSpec, TextEdit, Tx, col, el, oklch, row, text, text_input, tok};
6+
7+pub const WIDGET: Widget = Widget { title: "Board", size: (1100.0, 520.0), new: |_| Box::new(Board::default()) };
8+
9+pub const STATES: [&str; 7] = ["draft", "ready", "running", "review", "parked", "failed", "done"];
10+
11+#[derive(Default)]
12+pub struct Board {
13+ /// The quick-add field at the top of draft.
14+ add: TextEdit,
15+ /// The board's and each column's rect in window points, from layout.
16+ rect: [f32; 4],
17+ cols: [[f32; 4]; 7],
18+ /// The card being dragged: its ticket, the pointer in window points, and where on the card it was grabbed.
19+ drag: Option<Dragged>,
20+}
21+
22+#[derive(Clone, Copy)]
23+struct Dragged { id: u32, at: [f32; 2], grab: [f32; 2], w: f32, moved: bool }
24+
25+impl Board {
26+ /// The column under window point `p`.
27+ fn col_at(&self, p: [f32; 2]) -> Option<&'static str> {
28+ self.cols.iter().position(|r| p[0] >= r[0] && p[0] < r[0] + r[2] && p[1] >= r[1] && p[1] < r[1] + r[3]).map(|i| STATES[i])
29+ }
30+
31+ /// Where the dragged card would land: a column it can move to, or none.
32+ fn target(&self, from: &str) -> Option<&'static str> {
33+ let d = self.drag.filter(|d| d.moved)?;
34+ self.col_at(d.at).filter(|s| *s != from && *s != "running" && from != "running")
35+ }
36+}
37+
38+impl View for Board {
39+ fn view(&self, cx: &Cx) -> El {
40+ let t = tok::theme(true);
41+ let project = super::root::project_of(cx.id);
42+ let tickets: Vec<&Ticket> = cx.data.tickets.iter().filter(|k| k.project == project).collect();
43+ let dragged = self.drag.and_then(|d| tickets.iter().find(|k| k.id == d.id).copied());
44+ let target = dragged.and_then(|k| self.target(&k.state));
45+ let mut cols = row().key("columns").w_full().grow(1.0).min_h(0.0).gap(8.0);
46+ for (i, state) in STATES.iter().enumerate() {
47+ let mut cards: Vec<&Ticket> = tickets.iter().filter(|k| k.state == *state).copied().collect();
48+ cards.sort_by_key(|k| std::cmp::Reverse(k.since));
49+ let id = cx.id.to_owned();
50+ let mut list = col().w_full().gap(6.0);
51+ if *state == "draft" { list = list.child(quick_add(cx, &self.add, project)); }
52+ for k in &cards { list = list.child(card(cx, k, dragged.is_some_and(|d| d.id == k.id))); }
53+ cols = cols.child(col().key(format!("col-{state}")).grow(1.0).min_w(0.0).h_full().gap(8.0).padding(6.0).radius(8.0)
54+ .fill(if target == Some(state) { t.press } else { t.bg })
55+ .on_layout(move |h: &mut HostState, r: [f32; 4]| if let Some(b) = get::<Board>(h, &id) { b.cols[i] = r })
56+ .child(row().key(format!("head-{state}")).w_full().px(4.0).gap(6.0).center_y()
57+ .child(text(*state).font(tok::type_::LABEL).color(t.text))
58+ .child(el().grow(1.0))
59+ .child(text(cards.len().to_string()).font(tok::type_::LABEL).color(t.text_secondary)))
60+ .child(col().w_full().grow(1.0).min_h(0.0).scroll(ScrollSpec { stick_bottom: false }).child(list)));
61+ }
62+ let id = cx.id.to_owned();
63+ let mut board = col().w_full().h_full().gap(8.0)
64+ .on_layout(move |h: &mut HostState, r: [f32; 4]| if let Some(b) = get::<Board>(h, &id) { b.rect = r })
65+ .child(row().key("header").w_full().center_y().gap(8.0)
66+ .child(text("Board").font(tok::type_::TITLE).color(t.text))
67+ .child(text(project).font(tok::type_::LABEL).color(t.text_secondary))
68+ .child(el().grow(1.0))
69+ .child(text(format!("{} tickets", tickets.len())).font(tok::type_::LABEL).color(t.text_secondary))
70+ .child(canvas::maximize(cx))
71+ .child(canvas::close(cx, "Close board")))
72+ .child(cols);
73+ // The dragged card follows the pointer.
74+ if let (Some(d), Some(k)) = (self.drag.filter(|d| d.moved), dragged) {
75+ let (x, y) = (d.at[0] - d.grab[0] - self.rect[0], d.at[1] - d.grab[1] - self.rect[1]);
76+ board = board.child(face(k, cx.now).w(d.w).absolute(x, y).opacity(0.9).border(1.0, oklch(0.72, 0.14, 250.0)));
77+ }
78+ board
79+ }
80+}
81+
82+/// The field atop draft: Enter writes a new draft titled with what was typed.
83+fn quick_add(cx: &Cx, edit_: &TextEdit, project: &str) -> El {
84+ let t = tok::theme(true);
85+ let (id, project) = (cx.id.to_owned(), project.to_owned());
86+ text_input(edit_, tok::type_::LABEL).key("quick-add").single_line().w_full().px(8.0).py(6.0).radius(6.0).fill(t.card).color(t.text)
87+ .placeholder("New draft…", t.text_secondary)
88+ .on_edit(edit(cx.id, |b: &mut Board| &mut b.add))
89+ .on_submit(move |h: &mut HostState, _: &mut Tx| {
90+ let Some(b) = get::<Board>(h, &id) else { return };
91+ let words = b.add.text.trim().to_owned();
92+ b.add.clear();
93+ if !words.is_empty() { new_ticket(h, &project, &words, &words, "draft", &[]) }
94+ })
95+}
96+
97+/// A ticket's card: drag it to another column, or click it to open the ticket beside the board.
98+fn card(cx: &Cx, k: &Ticket, dragged: bool) -> El {
99+ let (id, ticket, from) = (cx.id.to_owned(), k.id, k.state.clone());
100+ face(k, cx.now).key(format!("card-{}", k.id)).w_full().role("button").label(format!("#{} {}", k.id, k.title)).hover(tok::theme(true).hover)
101+ .opacity(if dragged { 0.35 } else { 1.0 })
102+ .on_drag(move |h: &mut HostState, d: &mut Drag, _: &mut Tx| {
103+ let Some(b) = get::<Board>(h, &id) else { return };
104+ match d.phase {
105+ Phase::Down => b.drag = Some(Dragged { id: ticket, at: d.window_point(), grab: [d.x, d.y], w: d.w, moved: false }),
106+ Phase::Move => if let Some(g) = &mut b.drag { g.at = d.window_point(); g.moved |= d.dx.abs() + d.dy.abs() > 4.0 },
107+ Phase::Up => {
108+ let to = if d.cancelled() { None } else { b.target(&from) };
109+ let clicked = b.drag.take().is_some_and(|g| !g.moved) && !d.cancelled();
110+ let project = super::root::project_of(&id).to_owned();
111+ if let Some(to) = to { set_state(h, &project, ticket, to) }
112+ if clicked { open(h, &id, ticket) }
113+ }
114+ }
115+ })
116+}
117+
118+/// What a card shows: #id, the time in its state, and its title.
119+fn face(k: &Ticket, now: f64) -> El {
120+ let t = tok::theme(true);
121+ col().gap(4.0).padding(8.0).radius(6.0).fill(t.card)
122+ .child(row().w_full().gap(6.0)
123+ .child(text(format!("#{}", k.id)).font(tok::type_::LABEL).color(t.text_secondary))
124+ .child(el().grow(1.0))
125+ .child(text(ago(now, k.since)).font(tok::type_::LABEL).color(t.text_secondary)))
126+ .child(text(&k.title).font(tok::type_::LABEL).color(t.text).w_full().wrap().max_lines(3))
127+}
128+
129+/// Opens ticket `ticket` in a card beside board `board` on its canvas, or brings it to the front.
130+fn open(h: &mut HostState, board: &str, ticket: u32) {
131+ let Some((parent, key)) = board.rsplit_once('.') else { return };
132+ if let Some(c) = get::<Canvas>(h, parent) { c.open_beside("ticket", &format!("ticket-{ticket}"), super::ticket::WIDGET.size, key) }
133+}
134+
135+/// How long ago Unix time `at` was: 40s, 12m, 3h, 5d.
136+pub fn ago(now: f64, at: u64) -> String {
137+ let s = (now as u64).saturating_sub(at);
138+ match s {
139+ 0..60 => format!("{s}s"),
140+ 60..3600 => format!("{}m", s / 60),
141+ 3600..86400 => format!("{}h", s / 3600),
142+ _ => format!("{}d", s / 86400),
143+ }
144+}
templates/library/widgets/canvas.rs+31−36
@@ -34,8 +34,6 @@ pub struct Canvas {
3434 /// The canvas's laid-out size, kept as a "size" file: the app reloads widgets without
3535 /// laying out again, so `on_layout` only speaks when the size changes.
3636 size: (f32, f32),
37- /// The taskbar's Library toggle hid this desktop's library cards; kept as a "library-hidden" file.
38- library_hidden: bool,
3937 }
4038
4139 impl Canvas {
@@ -47,12 +45,11 @@ impl Canvas {
4745 let n = |i: usize| f.get(i)?.parse::<f32>().ok();
4846 Some(Child { kind: f.first()?.to_string(), key: f.get(1)?.to_string(), x: n(2)?, y: n(3)?, w: n(4)?, h: n(5)?, max: f.get(6) == Some(&"1") })
4947 }).collect();
50- let library_hidden = cx.dir.join("library-hidden").exists();
5148 let size = std::fs::read_to_string(cx.dir.join("size")).ok().and_then(|s| {
5249 let (w, h) = s.split_once(' ')?;
5350 Some((w.parse().ok()?, h.parse().ok()?))
5451 }).unwrap_or((0.0, 0.0));
55- Canvas { children, file, grab: None, size, library_hidden }
52+ Canvas { children, file, grab: None, size }
5653 }
5754
5855 fn save(&self) {
@@ -82,27 +79,19 @@ impl Canvas {
8279 /// Adds a `kind` of size `size` with its top-left at `at`.
8380 pub fn add(&mut self, kind: &str, at: (f32, f32), (w, h): (f32, f32)) {
8481 let key = (1..).map(|i| format!("{kind}{i}")).find(|k| !self.children.iter().any(|c| &c.key == k)).unwrap();
85- self.children.push(Child { kind: kind.into(), key, x: at.0, y: at.1, w, h, max: false });
86- self.save();
87- }
88-
89- /// Whether a `kind` is on the canvas.
90- pub fn has(&self, kind: &str) -> bool {
91- self.children.iter().any(|c| c.kind == kind)
82+ self.add_keyed(kind, key, at, (w, h));
9283 }
9384
94- /// Whether a library card shows here.
95- pub fn library_shown(&self) -> bool {
96- !self.library_hidden && self.has("library")
85+ fn add_keyed(&mut self, kind: &str, key: String, at: (f32, f32), (w, h): (f32, f32)) {
86+ self.children.push(Child { kind: kind.into(), key, x: at.0, y: at.1, w, h, max: false });
87+ self.save();
9788 }
9889
99- /// Hides or shows this desktop's library cards, putting one in the top-left if showing and there's none.
100- pub fn toggle_library(&mut self) {
101- let shown = self.library_shown();
102- if !shown && !self.has("library") { self.add("library", (24.0, 24.0), super::library::WIDGET.size) }
103- self.library_hidden = shown;
104- let flag = self.file.with_file_name("library-hidden");
105- let _ = if shown { std::fs::write(flag, "") } else { std::fs::remove_file(flag) };
90+ /// Adds a `kind` of size `size` near the top left, stepping down and right past anything already there.
91+ pub fn add_free(&mut self, kind: &str, size: (f32, f32)) {
92+ let mut at = (24.0, 24.0);
93+ while self.children.iter().any(|c| (c.x, c.y) == at) { at = (at.0 + 28.0, at.1 + 28.0) }
94+ self.add(kind, at, size);
10695 }
10796
10897 /// Takes the child keyed `key` off the canvas.
@@ -111,16 +100,31 @@ impl Canvas {
111100 self.save();
112101 }
113102
114- /// Adds a `kind` beside the child keyed `beside`: to its right if it fits, else to its left,
115- /// stepping down past anything already there.
103+ /// Adds a `kind` beside the child keyed `beside`: to its right if it fits, else against the
104+ /// canvas's right edge, stepping down past anything already there.
116105 pub fn add_beside(&mut self, kind: &str, size: (f32, f32), beside: &str) {
117- let Some(b) = self.children.iter().find(|c| c.key == beside) else { return };
106+ if let Some(at) = self.spot_beside(size, beside) { self.add(kind, at, size) }
107+ }
108+
109+ /// Brings the card keyed `key` to the front, or adds a `kind` keyed `key` beside the child keyed `beside`.
110+ pub fn open_beside(&mut self, kind: &str, key: &str, size: (f32, f32), beside: &str) {
111+ if let Some(i) = self.children.iter().position(|c| c.key == key) {
112+ let c = self.children.remove(i);
113+ self.children.push(c);
114+ return self.save();
115+ }
116+ if let Some(at) = self.spot_beside(size, beside) { self.add_keyed(kind, key.into(), at, size) }
117+ }
118+
119+ /// Where a card of `size` goes beside the child keyed `beside`.
120+ fn spot_beside(&self, size: (f32, f32), beside: &str) -> Option<(f32, f32)> {
121+ let b = self.children.iter().find(|c| c.key == beside)?;
118122 let (bx, by) = self.fit(b);
119123 let right = bx + b.w + 16.0;
120- let x = if self.size.0 <= 0.0 || right + size.0 <= self.size.0 { right } else { (bx - 16.0 - size.0).max(0.0) };
124+ let x = if self.size.0 <= 0.0 || right + size.0 <= self.size.0 { right } else { (self.size.0 - size.0).max(0.0) };
121125 let mut y = by;
122126 while self.children.iter().any(|c| c.x == x && c.y == y) { y += 28.0; }
123- self.add(kind, (x, y), size);
127+ Some((x, y))
124128 }
125129 }
126130
@@ -137,9 +141,7 @@ impl View for Canvas {
137141 canvas = canvas.center().child(text("Ctrl+click anywhere to make a widget").color(t.text_secondary));
138142 }
139143 // A discarded build's kinds go away, and come back if it's built again.
140- // The taskbar's Library toggle hides library cards.
141- let hidden = |c: &&Child| c.kind == "library" && self.library_hidden;
142- for c in self.children.iter().filter(|c| cx.kinds().iter().any(|(n, _)| *n == c.kind)).filter(|c| !hidden(c)) {
144+ for c in self.children.iter().filter(|c| cx.kinds().iter().any(|(n, _)| *n == c.kind)) {
143145 let (x, y, w, h) = self.rect(c);
144146 let radius = if c.max { 0.0 } else { 10.0 };
145147 let grip = |name: &str, g: Grip, cursor: Cursor| el().key(format!("resize-{name}")).cursor(cursor).on_drag(drag(cx.id, c.key.clone(), g));
@@ -157,13 +159,6 @@ impl View for Canvas {
157159 canvas
158160 }
159161
160- /// The shown desktop tells the taskbar's Library toggle, through the shared "library", whether its library shows.
161- fn update(&mut self, cx: &Cx) {
162- let active = cx.id.rsplit_once('.').is_some_and(|(_, k)| k == super::root::desktop(cx));
163- let v = if self.library_shown() { "shown" } else { "hidden" };
164- if active && cx.shared("library") != Some(v) { cx.act(move |l| l.share("library", v)) }
165- }
166-
167162 fn mount(&mut self, kind: &str, at: (f32, f32), cx: &Cx) -> bool {
168163 let (w, h) = cx.kinds().iter().find(|(n, _)| *n == kind).map(|(_, w)| w.size).filter(|s| s.0 > 0.0).unwrap_or((320.0, 240.0));
169164 self.add(kind, at, (w, h));
templates/library/widgets/editor.rs+1−2
@@ -212,8 +212,7 @@ fn newline(edit: &mut TextEdit) {
212212
213213 /// The folder of the project whose desktop holds this card: `root.canvas-<slug>.<key>`, or the widgets project on `root.canvas`.
214214 fn project_dir(cx: &Cx) -> PathBuf {
215- let desktop = cx.id.rsplit('.').nth(1).unwrap_or("");
216- let slug = desktop.strip_prefix("canvas-").unwrap_or("widgets");
215+ let slug = super::root::project_of(cx.id);
217216 cx.data.projects.iter().find(|p| p.slug == slug).map(|p| PathBuf::from(&p.path)).unwrap_or_default()
218217 }
219218
templates/library/widgets/root.rs+8−2
@@ -9,10 +9,11 @@ pub struct Root;
99
1010 impl View for Root {
1111 fn view(&self, cx: &Cx) -> El {
12- col().w_full().h_full()
13- .child(col().w_full().h(36.0).child(cx.child("titlebar", "titlebar")))
12+ // The title bar goes last, pinned to the top, so its Widgets dropdown draws above the canvas.
13+ col().w_full().h_full().pt(36.0)
1414 .child(col().w_full().grow(1.0).min_h(0.0).child(cx.child("canvas", &desktop(cx))))
1515 .child(col().w_full().h(44.0).child(cx.child("taskbar", "taskbar")))
16+ .child(col().absolute(0.0, 0.0).w_full().h(36.0).child(cx.child("titlebar", "titlebar")))
1617 }
1718 }
1819
@@ -24,3 +25,8 @@ pub fn desktop(cx: &Cx) -> String {
2425 _ => "canvas".into(),
2526 }
2627 }
28+
29+/// The project whose desktop holds instance `id` (`root.canvas-<slug>.<key>`): the widgets project on `root.canvas`.
30+pub fn project_of(id: &str) -> &str {
31+ id.rsplit('.').nth(1).and_then(|d| d.strip_prefix("canvas-")).unwrap_or("widgets")
32+}
templates/library/widgets/taskbar.rs+3−15
@@ -1,7 +1,7 @@
11 //! A taskbar along the bottom of the window: the widgets project pinned first, then every other
2-//! project, and a button that adds one. The library toggle sits beside the widgets project. A press shares "project", and root switches to its canvas.
2+//! project, and a button that adds one. A press shares "project", and root switches to its canvas.
33 //! A project's × forgets it from the bar: the first press arms it (red), a second within `ARMED` seconds forgets.
4-use super::{api::*, canvas::Canvas};
4+use super::api::*;
55 use rune::{El, FileDialogOptions, Tx, el, oklch, row, text, tok};
66 use std::path::PathBuf;
77
@@ -49,7 +49,7 @@ impl View for Taskbar {
4949 let item = |p: &Project| project(cx, p, active == Some(p.slug.as_str()), self.armed(&p.slug, cx.now));
5050 let mut bar = row().w_full().h_full().center_y().gap(4.0).px(8.0).fill(t.card).border_sides([0.0, 1.0, 0.0, 0.0], t.separator);
5151 if let Some(p) = cx.data.projects.iter().find(|p| p.slug == LIBRARY) {
52- bar = bar.child(item(p)).child(library_toggle(cx)).child(el().w(1.0).h(22.0).mx(4.0).fill(t.separator));
52+ bar = bar.child(item(p)).child(el().w(1.0).h(22.0).mx(4.0).fill(t.separator));
5353 }
5454 for p in cx.data.projects.iter().filter(|p| p.slug != LIBRARY && !self.forgotten.contains(&p.slug)) { bar = bar.child(item(p)); }
5555 bar.child(add_button(cx))
@@ -116,15 +116,3 @@ fn add_button(cx: &Cx) -> El {
116116 });
117117 })
118118 }
119-
120-/// Shows or hides the shown desktop's library cards; the canvas reports back through the shared "library".
121-fn library_toggle(cx: &Cx) -> El {
122- let t = tok::theme(true);
123- let shown = cx.shared("library") != Some("hidden");
124- let canvas = format!("{}.{}", cx.id.rsplit_once('.').map_or("root", |(p, _)| p), super::root::desktop(cx));
125- let b = row().key("toggle-library").w(34.0).h(34.0).center().radius(6.0).role("button")
126- .label(if shown { "Hide library" } else { "Show library" }).help(if shown { "Hide library" } else { "Show library" }).hover(t.hover)
127- .on_press_tx(move |h: &mut HostState, _: &mut Tx| if let Some(c) = get::<Canvas>(h, &canvas) { c.toggle_library() })
128- .child(text("▤").color(if shown { oklch(0.72, 0.14, 250.0) } else { t.text_secondary }));
129- if shown { b.fill(t.press) } else { b }
130-}
templates/library/widgets/ticket.rs+158−0
@@ -0,0 +1,158 @@
1+//! One ticket, opened from a board: its title and body (editable while it isn't running; Save
2+//! rewrites it), attached files, its conversation with times, and what its state allows next.
3+//! In review it shows the branch's diff stat; parked, the block and its recommendation.
4+use super::{api::*, board::ago, canvas};
5+use rune::{El, Family, ScrollSpec, TextEdit, Tx, col, el, oklch, row, text, text_input, tok};
6+use std::{path::PathBuf, sync::{Arc, Mutex}};
7+
8+pub const WIDGET: Widget = Widget { title: "Ticket", size: (480.0, 620.0), new: |cx| Box::new(TicketCard::load(cx)) };
9+
10+pub struct TicketCard {
11+ title: TextEdit,
12+ body: TextEdit,
13+ /// The title and body as conveyor last had them: the fields follow them until edited.
14+ base: (String, String),
15+ /// Unsaved edits, kept as a "draft" file (title, a line break, body) across reloads.
16+ draft: PathBuf,
17+ /// `git diff --stat HEAD...t-<id>`, run when the ticket entered review at this time.
18+ diff: Arc<Mutex<Option<String>>>,
19+ diff_for: u64,
20+}
21+
22+/// The ticket this card shows: its key is `ticket-<id>` on the project's desktop.
23+fn ticket<'a>(cx: &'a Cx) -> Option<&'a Ticket> {
24+ let id: u32 = cx.id.rsplit('.').next()?.strip_prefix("ticket-")?.parse().ok()?;
25+ let project = super::root::project_of(cx.id);
26+ cx.data.tickets.iter().find(|k| k.project == project && k.id == id)
27+}
28+
29+impl TicketCard {
30+ fn load(cx: &Cx) -> Self {
31+ let draft = cx.dir.join("draft");
32+ let (title, body) = std::fs::read_to_string(&draft).ok().and_then(|s| s.split_once('\n').map(|(a, b)| (a.to_owned(), b.to_owned())))
33+ .or_else(|| ticket(cx).map(|k| (k.title.clone(), k.body.clone()))).unwrap_or_default();
34+ let base = ticket(cx).map(|k| (k.title.clone(), k.body.clone())).unwrap_or_default();
35+ TicketCard { title: TextEdit::new(title), body: TextEdit::new(body), base, draft, diff: Arc::default(), diff_for: 0 }
36+ }
37+
38+ fn modified(&self) -> bool {
39+ (self.title.text.as_str(), self.body.text.as_str()) != (self.base.0.as_str(), self.base.1.as_str())
40+ }
41+}
42+
43+impl View for TicketCard {
44+ fn update(&mut self, cx: &Cx) {
45+ let Some(k) = ticket(cx) else { return };
46+ if (k.title.as_str(), k.body.as_str()) != (self.base.0.as_str(), self.base.1.as_str()) {
47+ if !self.modified() { (self.title, self.body) = (TextEdit::new(k.title.clone()), TextEdit::new(k.body.clone())) }
48+ self.base = (k.title.clone(), k.body.clone());
49+ }
50+ let draft = format!("{}\n{}", self.title.text, self.body.text);
51+ if !self.modified() { let _ = std::fs::remove_file(&self.draft); }
52+ else if std::fs::read_to_string(&self.draft).ok().as_deref() != Some(&draft) { let _ = std::fs::write(&self.draft, draft); }
53+ if k.state == "review" && self.diff_for != k.since {
54+ self.diff_for = k.since;
55+ let (out, path, branch) = (self.diff.clone(), cx.data.projects.iter().find(|p| p.slug == k.project).map(|p| p.path.clone()).unwrap_or_default(), format!("HEAD...t-{}", k.id));
56+ *out.lock().unwrap() = None;
57+ std::thread::spawn(move || {
58+ let r = std::process::Command::new("git").args(["diff", "--stat", &branch]).current_dir(&path).output();
59+ let s = match r {
60+ Ok(o) if o.status.success() => String::from_utf8_lossy(&o.stdout).trim_end().to_owned(),
61+ Ok(o) => String::from_utf8_lossy(&o.stderr).trim_end().to_owned(),
62+ Err(e) => format!("git: {e}"),
63+ };
64+ *out.lock().unwrap() = Some(if s.is_empty() { "No changes".into() } else { s });
65+ });
66+ }
67+ }
68+
69+ fn view(&self, cx: &Cx) -> El {
70+ let t = tok::theme(true);
71+ let Some(k) = ticket(cx) else {
72+ return col().w_full().h_full().center().gap(8.0).child(text("No ticket here: open one from a board").color(t.text_secondary)).child(canvas::close(cx, "Close"));
73+ };
74+ let running = k.state == "running";
75+ let label = |s: &str| text(s).font(tok::type_::LABEL).color(t.text_secondary);
76+ let field = |e: &TextEdit| text_input(e, tok::type_::BODY).w_full().px(8.0).py(6.0).radius(6.0).fill(t.bg).color(t.text);
77+ let mut body = col().w_full().gap(10.0);
78+ body = if running {
79+ body.child(text(&k.title).font(tok::type_::TITLE).color(t.text).w_full().wrap())
80+ .child(text(&k.body).color(t.text).w_full().wrap())
81+ .child(label("Running: editing waits until it settles"))
82+ } else {
83+ body.child(field(&self.title).key("title").single_line().on_edit(edit(cx.id, |c: &mut TicketCard| &mut c.title)))
84+ .child(field(&self.body).key("body").min_h(120.0).on_edit(edit(cx.id, |c: &mut TicketCard| &mut c.body)))
85+ };
86+ if !k.files.is_empty() {
87+ let mut files = col().key("files").w_full().gap(2.0).child(label("Files"));
88+ for f in &k.files {
89+ let path = f.clone();
90+ let name = std::path::Path::new(f).file_name().map_or(f.clone(), |n| n.to_string_lossy().into_owned());
91+ files = files.child(row().key(format!("file-{name}")).w_full().px(6.0).py(4.0).radius(5.0).role("button").label(name.as_str()).help(f.as_str()).hover(t.hover)
92+ .on_press_tx(move |_: &mut HostState, _: &mut Tx| { let _ = std::process::Command::new("xdg-open").arg(&path).spawn(); })
93+ .child(text(format!("▤ {name}")).font(tok::type_::LABEL).color(t.text).truncate()));
94+ }
95+ body = body.child(files);
96+ }
97+ if k.state == "review" {
98+ let diff = self.diff.lock().unwrap().clone().unwrap_or_else(|| "…".into());
99+ body = body.child(col().key("diff").w_full().gap(4.0).padding(8.0).radius(6.0).fill(t.bg)
100+ .child(text(format!("Branch t-{}", k.id)).font(tok::type_::LABEL).color(t.text))
101+ .child(text(diff).font(tok::type_::LABEL.family(Family::SystemMono)).color(t.text_secondary).w_full().wrap()));
102+ }
103+ if k.state == "parked" && let Some(b) = k.thread.iter().rev().find(|a| a.kind == "block") {
104+ body = body.child(col().key("block").w_full().gap(4.0).padding(8.0).radius(6.0).fill(t.bg).border(1.0, oklch(0.75, 0.14, 70.0))
105+ .child(text("Blocked").font(tok::type_::LABEL).color(oklch(0.8, 0.14, 70.0)))
106+ .child(text(&b.text).font(tok::type_::LABEL).color(t.text).w_full().wrap())
107+ .child(label("Answer it in the body, then Ready")));
108+ }
109+ let mut thread = col().key("thread").w_full().gap(6.0).child(label("Conversation"));
110+ for (i, a) in k.thread.iter().enumerate() {
111+ thread = thread.child(col().key(format!("entry-{i}")).w_full().gap(2.0)
112+ .child(row().w_full().gap(6.0).child(text(&a.kind).font(tok::type_::LABEL).color(t.text)).child(el().grow(1.0)).child(label(&ago(cx.now, a.at))))
113+ .child(text(&a.text).font(tok::type_::LABEL).color(t.text_secondary).w_full().wrap()));
114+ }
115+ col().w_full().h_full().gap(10.0)
116+ .child(row().key("header").w_full().center_y().gap(8.0)
117+ .child(text(format!("#{}", k.id)).font(tok::type_::TITLE).color(t.text))
118+ .child(row().px(8.0).py(2.0).radius(8.0).fill(t.press).child(text(&k.state).font(tok::type_::LABEL).color(t.text)))
119+ .child(label(&ago(cx.now, k.since)))
120+ .child(el().grow(1.0))
121+ .child(canvas::maximize(cx))
122+ .child(canvas::close(cx, "Close ticket")))
123+ .child(col().key("content").w_full().grow(1.0).min_h(0.0).scroll(ScrollSpec { stick_bottom: false }).child(body.child(thread)))
124+ .child(self.actions(cx, k))
125+ }
126+}
127+
128+impl TicketCard {
129+ /// Save while edited, and the moves the ticket's state allows.
130+ fn actions(&self, cx: &Cx, k: &Ticket) -> El {
131+ let mut bar = row().key("actions").w_full().gap(8.0).child(el().grow(1.0));
132+ if k.state != "running" && self.modified() { bar = bar.child(button(cx, k, "save", "Save", None, true)) }
133+ // A parked ticket goes back once its body has the answer: it differs from what the agent was given.
134+ let answered = k.thread.iter().rev().find(|a| a.kind == "prompt").is_none_or(|p| p.text.trim() != self.body.text.trim());
135+ match k.state.as_str() {
136+ "draft" => bar.child(button(cx, k, "ready", "Ready", Some("ready"), true)),
137+ "failed" => bar.child(button(cx, k, "retry", "Ready to retry", Some("ready"), true)),
138+ "parked" => bar.child(button(cx, k, "ready", "Ready", Some("ready"), answered)),
139+ "review" => bar.child(button(cx, k, "back", "Back to draft", Some("draft"), true)).child(button(cx, k, "done", "Done", Some("done"), true)),
140+ _ => bar,
141+ }
142+ }
143+}
144+
145+/// A button that saves any edits, then moves the ticket to `to`. Dimmed and inert unless `on`.
146+fn button(cx: &Cx, k: &Ticket, key: &str, label: &str, to: Option<&'static str>, on: bool) -> El {
147+ let t = tok::theme(true);
148+ let (id, project, ticket) = (cx.id.to_owned(), k.project.clone(), k.id);
149+ let b = row().key(key).h(28.0).px(12.0).center().radius(6.0).role("button").label(label).disabled(!on).fill(t.press)
150+ .child(text(label).font(tok::type_::LABEL).color(if on { t.text } else { t.text_secondary }));
151+ if !on { return b.opacity(0.5) }
152+ b.hover(t.hover).on_press_tx(move |h: &mut HostState, _: &mut Tx| {
153+ let Some(c) = get::<TicketCard>(h, &id) else { return };
154+ let edits = c.modified().then(|| (c.title.text.trim().to_owned(), c.body.text.clone()));
155+ if let Some((title, body)) = edits { edit_ticket(h, &project, ticket, &title, &body) }
156+ if let Some(to) = to { set_state(h, &project, ticket, to) }
157+ })
158+}
templates/library/widgets/titlebar.rs+31−7
@@ -1,10 +1,12 @@
1-//! The window's title bar: drag to move it, the running indicator centered, and its buttons.
1+//! The window's title bar: drag to move it, a Widgets button that drops down the library, the
2+//! running indicator centered, and its buttons.
23 use super::api::*;
3-use rune::{El, Tx, el, row, text, tok};
4+use rune::{Align, El, Side, Tx, col, el, oklch, row, text, tok};
45
5-pub const WIDGET: Widget = Widget { title: "Title bar", size: (0.0, 36.0), new: |_| Box::new(TitleBar) };
6+pub const WIDGET: Widget = Widget { title: "Title bar", size: (0.0, 36.0), new: |_| Box::new(TitleBar { open: false }) };
67
7-pub struct TitleBar;
8+/// `open`: the Widgets dropdown shows.
9+pub struct TitleBar { pub open: bool }
810
911 fn button(key: &'static str, label: &'static str, glyph: &'static str, f: impl Fn(&mut HostState, &mut Tx) + 'static) -> El {
1012 let t = tok::theme(true);
@@ -15,12 +17,34 @@ impl View for TitleBar {
1517 fn view(&self, cx: &Cx) -> El {
1618 let t = tok::theme(true);
1719 // Equal-growth sides (flex-basis 0, same padding) keep the indicator at the bar's true center.
18- row().w_full().h_full().center_y().fill(t.card).window_drag()
19- .child(row().grow(1.0).h_full().center_y().pl(14.0).child(text("Conveyor").font(tok::type_::TITLE).color(t.text)))
20+ let mut bar = row().w_full().h_full().center_y().fill(t.card).window_drag()
21+ .child(row().grow(1.0).h_full().center_y().gap(10.0).pl(14.0)
22+ .child(text("Conveyor").font(tok::type_::TITLE).color(t.text))
23+ .child(widgets_button(cx, self.open)))
2024 .child(cx.child("running", "running"))
2125 .child(row().grow(1.0).h_full().pl(14.0).child(el().grow(1.0))
2226 .child(button("min", "Minimize", "_", |_, tx| tx.minimize()))
2327 .child(button("max", "Maximize", "□", |_, tx| tx.toggle_maximized()))
24- .child(button("close", "Close", "×", |_, tx| tx.close_window())))
28+ .child(button("close", "Close", "×", |_, tx| tx.close_window())));
29+ if self.open {
30+ // A click outside (the button included) dismisses it, as Escape does.
31+ let id = cx.id.to_owned();
32+ bar = bar.child(col().key("widgets-menu").w(380.0).max_h(560.0).radius(8.0).fill(t.card).border(1.0, t.card_border)
33+ .shadow(8.0, 24.0, t.shadow).anchored_fit("widgets", Side::Bottom, Align::Start, 4.0)
34+ .modal(true, move |h: &mut HostState| if let Some(b) = get::<TitleBar>(h, &id) { b.open = false })
35+ .child(cx.child("widget_menu", "menu")));
36+ }
37+ bar
2538 }
2639 }
40+
41+/// The Widgets button: opens the dropdown, highlighted while it shows.
42+fn widgets_button(cx: &Cx, open: bool) -> El {
43+ let t = tok::theme(true);
44+ let b = row().key("widgets").h(26.0).px(10.0).gap(6.0).center_y().radius(6.0).role("button").label("Widgets")
45+ .help("Add a widget to this canvas").hover(t.hover)
46+ .on_press_tx(on(cx.id, |b: &mut TitleBar, _| b.open = !b.open))
47+ .child(text("◆").font(tok::type_::LABEL).color(if open { oklch(0.72, 0.14, 250.0) } else { t.text_secondary }))
48+ .child(text("Widgets").font(tok::type_::LABEL).color(t.text));
49+ if open { b.fill(t.press) } else { b }
50+}
templates/library/widgets/widget_menu.rs+37−0
@@ -0,0 +1,37 @@
1+//! The title bar's Widgets dropdown: every widget that can go on a canvas, with its title and
2+//! what it does. Clicking one adds it to the shown project's canvas and closes the dropdown.
3+use super::{api::*, canvas::Canvas, titlebar::TitleBar};
4+use rune::{El, ScrollSpec, Tx, col, oklch, row, text, tok};
5+
6+pub const WIDGET: Widget = Widget { title: "Widgets menu", size: (0.0, 0.0), new: |_| Box::new(WidgetMenu) };
7+
8+pub struct WidgetMenu;
9+
10+impl View for WidgetMenu {
11+ fn view(&self, cx: &Cx) -> El {
12+ let mut list = col().w_full().gap(2.0).padding(6.0);
13+ // Layouts (size 0) fill a parent, so they're not something to add.
14+ for (name, w) in cx.kinds().iter().filter(|(_, w)| w.size.0 > 0.0 && w.size.1 > 0.0) { list = list.child(item(cx, name, w)); }
15+ col().key("kinds").w_full().shrink().min_h(0.0).scroll(ScrollSpec { stick_bottom: false }).child(list)
16+ }
17+}
18+
19+/// One kind: a glyph, its title and description, as a button that adds it to the canvas root
20+/// shows and closes the dropdown (the title bar, this instance's parent).
21+fn item(cx: &Cx, name: &'static str, w: &Widget) -> El {
22+ let t = tok::theme(true);
23+ let about = cx.about(name);
24+ let r = row().key(format!("kind-{name}")).w_full().px(10.0).py(8.0).gap(10.0).radius(6.0)
25+ .child(text("◆").color(oklch(0.72, 0.14, 250.0)))
26+ .child(col().grow(1.0).min_w(0.0).gap(2.0)
27+ .child(text(w.title).font(tok::type_::BODY).color(t.text).truncate())
28+ .child(text(if about.is_empty() { format!("{name}.rs") } else { about.to_owned() })
29+ .font(tok::type_::LABEL).color(t.text_secondary).w_full().wrap()));
30+ let (bar, size) = (cx.id.rsplit_once('.').map_or("", |(p, _)| p).to_owned(), w.size);
31+ let canvas = format!("{}.{}", bar.rsplit_once('.').map_or("root", |(p, _)| p), super::root::desktop(cx));
32+ r.role("button").label(format!("Add {}", w.title)).hover(t.hover)
33+ .on_press_tx(move |h: &mut HostState, _: &mut Tx| {
34+ if let Some(c) = get::<Canvas>(h, &canvas) { c.add_free(name, size) }
35+ if let Some(b) = get::<TitleBar>(h, &bar) { b.open = false }
36+ })
37+}