xonecas.io
8447
Co

conveyor / commit 85b362c

Spike: the library is the whole UI; Ctrl+click is the only core tool

The app draws the library's `root` widget and nothing else. Frames, title bars,
badges, menus and canvas placement leave the core: the window chrome and the
canvas are now ordinary widgets (root, titlebar, canvas) the builder can change.

- api v3: widgets nest (cx.child), accept mounts, share values, read
  conveyor's projects/tickets/activity, call conveyord, animate.
- Core: a Ctrl-held inspector layer picks the instance under the pointer above
  all widget controls, a prompt form shows that kind's conversation, and
  transient status pills and reply toasts replace permanent chrome.
- conveyord: build tickets carry the clicked instance chain; an activity ring
  feeds widgets; a merge that doesn't build is reset, so main always builds.
- conveyor-idea.md: the builder must make widgets of any shape, click to
  create, click to edit.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-09 85b362cfda700251261744e69683736d49f21b55 parent caf16fc

28 files changed

This diff is too big to show in full. The first 1000 lines are below, and every file is listed with its counts.

conveyor-idea.md+2−0
@@ -63,6 +63,8 @@ A linux/mac desktop app, where:
6363 - We can later provide some basic widgets. But I rather build my own as we go.
6464
6565 Starter widget: CTRL+left click -> floating form to submit a prompt into the loop.
66+This is the building tool, it needs to allow me to create widgets of all shapes and sizes. So I can build widgets for: listing my projects, tabs, tiling panes, a text editor, a graphic visualization, etc...
67+It needs to be a closed loop, click to create, click to edit. This mod click is the basic building tool.
6668
6769 Why: in some projects I need the agent to render modeled data, others might be a video game. Both cases might need dedicated widgets that we build for that scenario.
6870
crates/conveyor-app/src/acts.rs+0−39
@@ -1,39 +0,0 @@
1-//! What frames ask of the app (api::Act), carried out on the canvas and saved by conveyord.
2-use crate::{canvas::State, client, widgets::api::{Act, Chrome, Host, View}};
3-use serde_json::json;
4-
5-pub fn chrome(s: &str) -> Chrome {
6- match s { "shown" => Chrome::Shown, "hidden" => Chrome::Hidden, _ => Chrome::Hover }
7-}
8-
9-fn chrome_name(c: Chrome) -> &'static str {
10- match c { Chrome::Shown => "shown", Chrome::Hover => "hover", Chrome::Hidden => "hidden" }
11-}
12-
13-impl Host for State {
14- fn widget(&mut self, id: u32) -> Option<&mut dyn View> {
15- self.widgets.get_mut(&id).map(|(_, w)| w.as_mut())
16- }
17-
18- fn spare(&mut self) -> &mut rune::TextEdit {
19- &mut self.spare
20- }
21-
22- fn act(&mut self, id: u32, a: Act) {
23- self.menu = None;
24- if a == Act::Notes {
25- if !self.notes.remove(&id) { self.notes.insert(id); }
26- return;
27- }
28- let (top, bottom) = self.snap.canvas.iter().fold((0, 0), |(t, b), p| (t.max(p.z + 1), b.min(p.z - 1)));
29- let Some(p) = self.snap.canvas.iter_mut().find(|p| p.id == id) else { return };
30- let set = match a {
31- Act::Maximize | Act::Restore => { p.maximized = a == Act::Maximize; json!({"maximized": p.maximized}) }
32- Act::Front => { p.z = top; json!({"z": top}) }
33- Act::Back => { p.z = bottom; json!({"z": bottom}) }
34- Act::Chrome(c) => { p.chrome = chrome_name(c).into(); json!({"chrome": p.chrome}) }
35- Act::Notes => unreachable!(),
36- };
37- client::frame(id, set);
38- }
39-}
crates/conveyor-app/src/app.rs+137−0
@@ -0,0 +1,137 @@
1+//! The app's state and loop. It draws the library's `root` widget and three things of its own
2+//! above it: the Ctrl inspector, the prompt form, and build status. Everything else is widgets.
3+use crate::{client, form::{self, Form}, inspect, status};
4+use crate::widgets::api::{Host, Live};
5+use rune::{El, Tx, Waker, el};
6+use serde_json::Value;
7+use std::{cell::RefCell, collections::BTreeSet, path::{Path, PathBuf}, sync::{Arc, Mutex}, time::{Duration, SystemTime}};
8+
9+pub struct State {
10+ pub live: Live,
11+ /// conveyord's last snapshot: builds and their threads.
12+ pub snap: Value,
13+ pub connected: bool,
14+ inbox: Arc<Mutex<Option<Option<Value>>>>,
15+ /// The binary at launch and its mtime. Read once: after cargo replaces it,
16+ /// current_exe() names the deleted file.
17+ exe: Option<PathBuf>,
18+ built: Option<SystemTime>,
19+ /// Ctrl is held: the inspector is up.
20+ pub ctrl: bool,
21+ /// The pointer, in window points.
22+ pub pointer: (f32, f32),
23+ /// The widget instances under the pointer, innermost first, and the element's key.
24+ pub picked: Vec<String>,
25+ pub element: String,
26+ /// Each picked instance's rect, as of the last render.
27+ pub rects: RefCell<Vec<(String, [f32; 4])>>,
28+ pub form: Option<Form>,
29+ /// What the form's field binds to in the frame it closes.
30+ pub spare: rune::TextEdit,
31+ /// Builds whose reply was dismissed, and builds whose new widgets were placed.
32+ pub seen: BTreeSet<u64>,
33+ placed: BTreeSet<u64>,
34+}
35+
36+impl Host for State {
37+ fn live(&mut self) -> &mut Live {
38+ &mut self.live
39+ }
40+}
41+
42+fn mtime(p: &Path) -> Option<SystemTime> {
43+ std::fs::metadata(p).ok()?.modified().ok()
44+}
45+
46+fn ids(base: &Path, name: &str) -> Option<BTreeSet<u64>> {
47+ Some(std::fs::read_to_string(base.join(name)).ok()?.split_whitespace().filter_map(|w| w.parse().ok()).collect())
48+}
49+
50+pub fn save_ids(base: &Path, name: &str, set: &BTreeSet<u64>) {
51+ let _ = std::fs::write(base.join(name), set.iter().map(|i| format!("{i}\n")).collect::<String>());
52+}
53+
54+pub fn init() -> State {
55+ let base = PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".local/share/conveyor/app");
56+ let _ = std::fs::create_dir_all(&base);
57+ State { seen: ids(&base, "seen").unwrap_or_default(), placed: ids(&base, "placed").unwrap_or_default(), live: Live::new(base),
58+ snap: Value::Null, connected: false, inbox: Default::default(), exe: None, built: None, ctrl: false, pointer: (0.0, 0.0),
59+ picked: vec![], element: String::new(), rects: RefCell::new(vec![]), form: None, spare: rune::TextEdit::new("") }
60+}
61+
62+/// Polls conveyord once a second on a thread. Every poll also re-renders, for clocks.
63+pub fn setup(s: &mut State, waker: Waker) {
64+ s.exe = std::env::current_exe().ok();
65+ s.built = s.exe.as_deref().and_then(mtime);
66+ let inbox = s.inbox.clone();
67+ std::thread::spawn(move || loop {
68+ *inbox.lock().unwrap() = Some(client::state());
69+ waker();
70+ std::thread::sleep(Duration::from_secs(1));
71+ });
72+}
73+
74+pub fn poll(s: &mut State, _t: f64, tx: &mut Tx) -> bool {
75+ let made = s.live.make_wanted();
76+ let mut again = made;
77+ if let Some(snap) = s.inbox.lock().unwrap().take() {
78+ s.connected = snap.is_some();
79+ if let Some(snap) = snap {
80+ s.live.data = client::data(&snap);
81+ s.snap = snap;
82+ }
83+ again = true;
84+ }
85+ if !made { place(s); }
86+ for r in s.live.take_outbox() { client::send(r); }
87+ s.live.save();
88+ if s.live.animating() { tx.wake_after(Duration::from_millis(16)); }
89+ restart(s);
90+ again
91+}
92+
93+/// Gives each new widget kind a finished build made a place: the widget clicked takes it, or
94+/// one of its parents. Kinds already on screen (a parent the build changed shows them) are
95+/// left alone.
96+fn place(s: &mut State) {
97+ let Some(builds) = s.snap["builds"].as_array() else { return };
98+ if s.live.kind("root").is_none() { return; }
99+ let first_run = !s.live.base().join("placed").exists();
100+ for b in builds.iter().filter(|b| b["state"] == "done") {
101+ let id = b["id"].as_u64().unwrap_or(0);
102+ if !s.placed.insert(id) || first_run { continue; }
103+ let targets: Vec<(String, (f32, f32))> = b["targets"].as_array().into_iter().flatten()
104+ .filter_map(|t| Some((t[0].as_str()?.to_owned(), (t[1].as_f64()? as f32, t[2].as_f64()? as f32)))).collect();
105+ for kind in b["created"].as_array().into_iter().flatten().filter_map(Value::as_str) {
106+ if s.live.ids(kind).is_empty() && s.live.mount(&targets, kind).is_none() {
107+ eprintln!("no widget kept the new `{kind}`");
108+ }
109+ }
110+ }
111+ save_ids(s.live.base(), "placed", &s.placed);
112+}
113+
114+/// conveyord rebuilt the app with a changed library: become the new binary, in place.
115+fn restart(s: &mut State) {
116+ let Some(exe) = &s.exe else { return };
117+ let Some(t) = mtime(exe) else { return };
118+ if Some(t) == s.built { return; }
119+ use std::os::unix::process::CommandExt;
120+ let err = std::process::Command::new(exe).args(std::env::args().skip(1)).exec();
121+ eprintln!("restart failed: {err}");
122+ s.built = Some(t);
123+}
124+
125+pub fn on_modifiers(s: &mut State, mods: rune::Mods, tx: &mut Tx) {
126+ s.ctrl = mods.ctrl;
127+ if s.ctrl { inspect::pick(s, tx); }
128+}
129+
130+pub fn view(s: &State, rcx: &mut rune::Cx<State>) -> El {
131+ let mut app = el().key("app").w_full().h_full()
132+ .child(el().key("content").w_full().h_full().child(s.live.render("root", "root"))
133+ .on_pointer_move_local(|s: &mut State, e: rune::PointerEvent, tx: &mut Tx| { s.pointer = (e.window_x, e.window_y); tx.live_only(); }));
134+ if s.ctrl && s.form.is_none() { app = app.child(inspect::view(s, rcx)); }
135+ if let Some(f) = &s.form { app = app.child(form::view(s, f, rcx)); }
136+ app.child(status::view(s))
137+}
crates/conveyor-app/src/canvas.rs+0−91
@@ -1,91 +0,0 @@
1-//! The canvas: the app's state, its link to conveyord, and the widgets drawn in stacking order.
2-use crate::{client::{self, Snapshot}, live, menu, place, prompt, titlebar, widgets::api::View};
3-use rune::{El, TextEdit, Tx, Waker, col, el, text, tok};
4-use std::{collections::{HashMap, HashSet}, path::{Path, PathBuf}, sync::{Arc, Mutex}, time::{Duration, SystemTime}};
5-
6-pub struct State {
7- pub snap: Snapshot,
8- connected: bool,
9- /// The pointer, in canvas points.
10- pub pointer: (f32, f32),
11- /// Where the prompt is open, and the widget it follows up on, if one was Ctrl+clicked.
12- pub prompt_at: Option<(f32, f32, Option<u32>)>,
13- pub prompt: TextEdit,
14- inbox: Arc<Mutex<Option<Option<Snapshot>>>>,
15- /// The binary at launch and its mtime. Read once: after cargo replaces it,
16- /// current_exe() names the deleted file.
17- exe: Option<PathBuf>,
18- built: Option<SystemTime>,
19- /// A widget's position when the drag on it started.
20- pub drag: Option<(f32, f32)>,
21- pub hovered: Option<u32>,
22- /// Widgets whose conversation is open.
23- pub notes: HashSet<u32>,
24- /// A widget's right-click menu, and where.
25- pub menu: Option<(u32, f32, f32)>,
26- /// Each built widget's own state, by widget id, with the widget's name.
27- pub widgets: HashMap<u32, (String, Box<dyn View>)>,
28- /// What a text field binds to while its widget isn't there.
29- pub spare: TextEdit,
30-}
31-
32-fn mtime(p: &Path) -> Option<SystemTime> {
33- std::fs::metadata(p).ok()?.modified().ok()
34-}
35-
36-pub fn init() -> State {
37- State { snap: Snapshot::default(), connected: false, pointer: (0.0, 0.0), prompt_at: None, prompt: TextEdit::new(""),
38- inbox: Default::default(), exe: None, built: None, drag: None, hovered: None, notes: HashSet::new(), menu: None,
39- widgets: HashMap::new(), spare: TextEdit::new("") }
40-}
41-
42-/// Polls conveyord once a second on a thread. Every poll also re-renders, for clocks.
43-pub fn setup(s: &mut State, waker: Waker) {
44- s.exe = std::env::current_exe().ok();
45- s.built = s.exe.as_deref().and_then(mtime);
46- let inbox = s.inbox.clone();
47- std::thread::spawn(move || loop {
48- *inbox.lock().unwrap() = Some(client::state());
49- waker();
50- std::thread::sleep(Duration::from_secs(1));
51- });
52-}
53-
54-pub fn poll(s: &mut State, _t: f64, _tx: &mut Tx) -> bool {
55- let Some(snap) = s.inbox.lock().unwrap().take() else { return false };
56- s.connected = snap.is_some();
57- // Mid-drag, the daemon's copy would snap the widget back.
58- if let Some(snap) = snap && s.drag.is_none() { s.snap = snap; }
59- live::sync(s);
60- // conveyord rebuilt the app with a new widget: become the new binary, in place.
61- if let Some(exe) = &s.exe && let Some(t) = mtime(exe) && Some(t) != s.built {
62- use std::os::unix::process::CommandExt;
63- let err = std::process::Command::new(exe).args(std::env::args().skip(1)).exec();
64- eprintln!("restart failed: {err}");
65- s.built = Some(t);
66- }
67- true
68-}
69-
70-pub fn view(s: &State, rcx: &mut rune::Cx<State>) -> El {
71- let t = tok::theme(true);
72- let tickets = live::tickets(s);
73- let area = rcx.layout("canvas").map_or((1400.0, 864.0), |r| (r[2], r[3]));
74- let mut canvas = el().key("canvas").role("canvas").label("Canvas").w_full().grow(1.0).min_h(0.0).fill(t.bg)
75- .on_pointer_move_local(|s: &mut State, e: rune::PointerEvent, tx: &mut Tx| { s.pointer = (e.x, e.y); tx.live_only(); })
76- .on_press_tx(|s: &mut State, tx: &mut Tx| {
77- s.menu = None;
78- if tx.mods().ctrl { let at = s.pointer; prompt::open(s, at, None) }
79- });
80- if s.snap.canvas.is_empty() && s.prompt_at.is_none() {
81- canvas = canvas.child(col().w_full().h_full().center().child(text("Ctrl+click anywhere to make a widget").color(t.text_secondary)));
82- }
83- let mut order: Vec<_> = s.snap.canvas.iter().collect();
84- // A widget with its conversation open draws on top, so the panel isn't covered.
85- order.sort_by_key(|p| (s.notes.contains(&p.id), p.z));
86- for p in order { canvas = canvas.child(place::view(s, p, &tickets, area)); }
87- if let Some((x, y, about)) = s.prompt_at { canvas = canvas.child(prompt::view(s, x, y, about)); }
88- if let Some((id, x, y)) = s.menu { canvas = canvas.child(menu::view(s, id, x, y)); }
89- let status = if s.connected { String::new() } else { "conveyord isn't running".into() };
90- col().key("root").w_full().h_full().fill(t.bg).child(titlebar::bar(status)).child(canvas)
91-}
crates/conveyor-app/src/client.rs+20−51
@@ -1,66 +1,35 @@
1-//! Talks to conveyord over its socket. The app holds no state of its own beyond what it shows,
2-//! and everything it does is a request here, so a script can do the same.
3-use serde::Deserialize;
1+//! Talks to conveyord over its socket, and turns its snapshot into what widgets read.
2+use crate::widgets::api::{Activity, Data, Project, Ticket};
43 use serde_json::{Value, json};
54 use std::{io::{BufRead, BufReader, Write}, os::unix::net::UnixStream, path::PathBuf};
65
7-#[derive(Deserialize, Default, Clone)]
8-pub struct Snapshot {
9- pub tickets: Vec<Ticket>,
10- pub canvas: Vec<Placed>,
11-}
12-
13-#[derive(Deserialize, Clone)]
14-pub struct Ticket {
15- pub project: String,
16- pub id: u32,
17- pub title: String,
18- pub state: String,
19-}
20-
21-/// A widget on the canvas, with its frame settings and its conversation.
22-#[derive(Deserialize, Clone)]
23-pub struct Placed {
24- pub id: u32,
25- pub x: f32,
26- pub y: f32,
27- pub z: i32,
28- pub maximized: bool,
29- pub chrome: String,
30- pub widget: Option<String>,
31- /// The latest ticket's state and title.
32- pub state: String,
33- pub title: String,
34- pub thread: Vec<Entry>,
35-}
36-
37-#[derive(Deserialize, Clone)]
38-pub struct Entry {
39- pub ticket: u32,
40- pub kind: String,
41- pub text: String,
42-}
43-
44-fn call(req: Value) -> Option<Value> {
6+/// One request, one reply line.
7+pub fn call(req: &str) -> Option<Value> {
458 let path = std::env::var("XDG_RUNTIME_DIR").map(PathBuf::from).unwrap_or_else(|_| "/tmp".into()).join("conveyor.sock");
469 let mut c = UnixStream::connect(path).ok()?;
47- writeln!(c, "{req}").ok()?;
10+ writeln!(c, "{}", req.replace('\n', " ")).ok()?;
4811 let mut line = String::new();
4912 BufReader::new(c).read_line(&mut line).ok()?;
5013 serde_json::from_str(&line).ok()
5114 }
5215
53-pub fn state() -> Option<Snapshot> {
54- serde_json::from_value(call(json!({"op": "state"}))?).ok()
16+/// Sends a request without waiting on it, from a thread: the UI never blocks on conveyord.
17+pub fn send(req: String) {
18+ std::thread::spawn(move || if call(&req).is_none() { eprintln!("conveyord didn't answer: {req}") });
5519 }
5620
57-pub fn widget(prompt: &str, x: f32, y: f32, about: Option<u32>) -> Option<u32> {
58- call(json!({"op": "widget", "prompt": prompt, "x": x, "y": y, "about": about}))?["id"].as_u64().map(|id| id as u32)
21+pub fn state() -> Option<Value> {
22+ call(&json!({"op": "state"}).to_string())
5923 }
6024
61-/// Frame settings: any of x, y, z, maximized, chrome.
62-pub fn frame(id: u32, mut set: Value) {
63- set["op"] = json!("frame");
64- set["id"] = json!(id);
65- call(set);
25+/// The snapshot's projects, tickets and activity, as the library's types.
26+pub fn data(v: &Value) -> Data {
27+ let s = |v: &Value, k: &str| v[k].as_str().unwrap_or("").to_owned();
28+ let n = |v: &Value, k: &str| v[k].as_u64().unwrap_or(0);
29+ let all = |k: &str| v[k].as_array().cloned().unwrap_or_default();
30+ Data {
31+ projects: all("projects").iter().map(|p| Project { slug: s(p, "slug"), path: s(p, "path"), slots: n(p, "slots") as u32 }).collect(),
32+ tickets: all("tickets").iter().map(|t| Ticket { project: s(t, "project"), id: n(t, "id") as u32, title: s(t, "title"), state: s(t, "state") }).collect(),
33+ activity: all("activity").iter().map(|a| Activity { at: n(a, "at"), project: s(a, "project"), ticket: n(a, "ticket") as u32, kind: s(a, "kind"), text: s(a, "text") }).collect(),
34+ }
6635 }
crates/conveyor-app/src/form.rs+75−0
@@ -0,0 +1,75 @@
1+//! The prompt a Ctrl+click opens: what was clicked, what's been said about that widget so far,
2+//! and a field for what to do next. Enter sends, Shift+Enter breaks the line, Esc cancels.
3+use crate::{app::State, client};
4+use rune::{El, Key, ScrollSpec, TextEdit, TextStyle, Tx, col, text, text_input, tok};
5+use serde_json::{Value, json};
6+
7+pub struct Form {
8+ /// Where it opened, in window points.
9+ pub at: (f32, f32),
10+ pub kind: String,
11+ /// The instance clicked, then its parents, each with the click in its own points.
12+ pub targets: Vec<(String, f32, f32)>,
13+ pub element: String,
14+ pub text: TextEdit,
15+}
16+
17+pub fn open(s: &mut State) {
18+ let (px, py) = s.pointer;
19+ let targets: Vec<_> = s.rects.borrow().iter().map(|(id, r)| (id.clone(), px - r[0], py - r[1])).collect();
20+ let kind = targets.first().and_then(|t| s.live.kind(&t.0)).unwrap_or("root").to_owned();
21+ let mut text = TextEdit::new("");
22+ text.focused = true;
23+ s.form = Some(Form { at: s.pointer, kind, targets, element: s.element.clone(), text });
24+}
25+
26+fn submit(s: &mut State, tx: &mut Tx) {
27+ tx.blur();
28+ let Some(f) = s.form.take() else { return };
29+ if f.text.text.trim().is_empty() { return; }
30+ client::send(json!({"op": "widget", "prompt": f.text.text, "kind": f.kind, "targets": f.targets, "element": f.element,
31+ "tree": s.live.tree(), "shared": s.live.shared_line()}).to_string());
32+}
33+
34+/// What's been said about `kind`: each build asked from it or that changed it.
35+fn thread<'a>(s: &'a State, kind: &str) -> Vec<&'a Value> {
36+ s.snap["builds"].as_array().into_iter().flatten()
37+ .filter(|b| b["kind"] == kind || b["changed"].as_array().is_some_and(|c| c.iter().any(|k| k == kind)))
38+ .flat_map(|b| b["thread"].as_array().into_iter().flatten()).collect()
39+}
40+
41+fn entry(e: &Value) -> El {
42+ let t = tok::theme(true);
43+ let kind = e["kind"].as_str().unwrap_or("");
44+ let color = match kind { "prompt" => t.text, "block" | "error" => tok::accent(1, true), _ => t.text_secondary };
45+ let who = if kind == "prompt" { "you".into() } else { format!("#{} {kind}", e["ticket"]) };
46+ col().w_full().gap(2.0)
47+ .child(text(who).font(tok::type_::LABEL).color(t.text_secondary))
48+ .child(text(e["text"].as_str().unwrap_or("").to_owned()).color(color).w_full())
49+}
50+
51+pub fn view(s: &State, f: &Form, rcx: &mut rune::Cx<State>) -> El {
52+ let t = tok::theme(true);
53+ let (ww, wh) = rcx.layout("app").map_or((1400.0, 900.0), |r| (r[2], r[3]));
54+ let (w, h) = (420.0, 360.0);
55+ let at = ((f.at.0).min(ww - w - 8.0).max(8.0), (f.at.1).min(wh - h - 8.0).max(8.0));
56+ let target = f.targets.first().map_or("root", |t| t.0.as_str());
57+ let mut history = col().w_full().gap(10.0);
58+ let entries = thread(s, &f.kind);
59+ if entries.is_empty() { history = history.child(text(format!("Nothing asked about `{}` yet.", f.kind)).color(t.text_secondary)); }
60+ for e in entries { history = history.child(entry(e)); }
61+ col().key("form").w(w).h(h).absolute(at.0, at.1).radius(10.0).fill(t.card).padding(12.0).gap(8.0).focus_ring(2.0, 0.0, tok::accent(0, true))
62+ .child(text(format!("{} · {target}", f.kind)).font(tok::type_::LABEL).color(t.text_secondary))
63+ .child(col().key("form-thread").w_full().grow(1.0).min_h(0.0).scroll(ScrollSpec { stick_bottom: true }).child(history))
64+ .child(text_input(&f.text, TextStyle::new(14.0, 400.0)).key("form-input").label("Prompt").w_full().h(84.0)
65+ .padding(6.0).radius(6.0).fill(t.bg).color(t.text)
66+ .placeholder("Change this, or ask for a new widget here… Enter sends, Shift+Enter new line, Esc cancels", t.text_secondary)
67+ .on_edit(|s: &mut State| { if s.form.is_none() { return &mut s.spare; } &mut s.form.as_mut().unwrap().text })
68+ .on_submit(submit)
69+ .on_input_key(|s: &mut State, e: &rune::KeyEvent, tx| {
70+ if !matches!(e.key, Key::Escape) { return false; }
71+ s.form = None;
72+ tx.blur();
73+ true
74+ }))
75+}
crates/conveyor-app/src/inspect.rs+35−0
@@ -0,0 +1,35 @@
1+//! The building tool's eye: while Ctrl is held, a layer over the whole window outlines the
2+//! widget under the pointer and its parents, and takes the click, so no widget's own controls
3+//! can swallow it. A click opens the prompt about that widget.
4+use crate::{app::State, form};
5+use rune::{El, Tx, el, text, tok};
6+
7+/// Finds the widget instances under the pointer: each renders keyed `w:<id>`.
8+pub fn pick(s: &mut State, tx: &mut Tx) {
9+ let (x, y) = s.pointer;
10+ tx.element_at_in("content", x, y, |s: &mut State, picked, _| {
11+ let Some(p) = picked else { (s.picked, s.element) = (vec![], String::new()); return };
12+ s.picked = p.path().split('/').filter_map(|seg| seg.strip_prefix("w:")).rev().map(String::from).collect();
13+ s.element = p.key().filter(|k| !k.starts_with("w:")).unwrap_or("").to_owned();
14+ });
15+}
16+
17+pub fn view(s: &State, rcx: &mut rune::Cx<State>) -> El {
18+ let accent = tok::accent(0, true);
19+ let t = tok::theme(true);
20+ let rects: Vec<(String, [f32; 4])> = s.picked.iter().filter_map(|id| Some((id.clone(), rcx.layout(&format!("w:{id}"))?))).collect();
21+ let mut layer = el().key("inspect").w_full().h_full().absolute(0.0, 0.0)
22+ .on_pointer_move_local(|s: &mut State, e: rune::PointerEvent, tx: &mut Tx| { s.pointer = (e.window_x, e.window_y); pick(s, tx); })
23+ .on_press_tx(|s: &mut State, _| form::open(s));
24+ for (i, (id, [x, y, w, h])) in rects.iter().enumerate().rev() {
25+ let kind = s.live.kind(id).unwrap_or("?");
26+ let (width, alpha) = if i == 0 { (2.0, 1.0) } else { (1.0, 0.35) };
27+ layer = layer.child(el().w(*w).h(*h).absolute(*x, *y).border(width, accent.alpha(alpha)).radius(4.0));
28+ if i == 0 {
29+ layer = layer.child(el().absolute(*x, (*y - 22.0).max(0.0)).h(20.0).px(8.0).center_y().radius(4.0).fill(accent)
30+ .child(text(format!("{kind} · {id} · {}", s.element)).font(tok::type_::LABEL).color(t.bg)));
31+ }
32+ }
33+ *s.rects.borrow_mut() = rects;
34+ layer
35+}
crates/conveyor-app/src/live.rs+0−33
@@ -1,33 +0,0 @@
1-//! The widgets' own state: one instance per built widget on the canvas, made when it appears
2-//! (or the app starts) and dropped when it goes. Each gets a folder that outlives restarts.
3-use crate::{canvas::State, widgets::{self, api::{Cx, TicketInfo}}};
4-use std::{path::PathBuf, time::{SystemTime, UNIX_EPOCH}};
5-
6-pub fn dir(id: u32) -> PathBuf {
7- PathBuf::from(std::env::var("HOME").unwrap_or_default()).join(".local/share/conveyor/widgets").join(id.to_string())
8-}
9-
10-pub fn now() -> f64 {
11- SystemTime::now().duration_since(UNIX_EPOCH).map_or(0.0, |d| d.as_secs_f64())
12-}
13-
14-pub fn tickets(s: &State) -> Vec<TicketInfo> {
15- s.snap.tickets.iter().map(|t| TicketInfo { project: t.project.clone(), id: t.id, state: t.state.clone(), title: t.title.clone() }).collect()
16-}
17-
18-/// Matches the instances to the canvas: new widgets get one, removed ones lose theirs.
19-pub fn sync(s: &mut State) {
20- let built: Vec<(u32, &str)> = s.snap.canvas.iter()
21- .filter_map(|p| Some((p.id, p.widget.as_deref()?)))
22- .collect();
23- s.widgets.retain(|id, (name, _)| built.iter().any(|(i, n)| i == id && n == name));
24- let tickets = tickets(s);
25- for (id, name) in built {
26- if s.widgets.contains_key(&id) { continue; }
27- let Some((_, w)) = widgets::ALL.iter().find(|(n, _)| *n == name) else { continue };
28- let dir = dir(id);
29- let _ = std::fs::create_dir_all(&dir);
30- let state = (w.new)(&Cx { id, now: now(), tickets: &tickets, dir: &dir });
31- s.widgets.insert(id, (name.to_owned(), state));
32- }
33-}
crates/conveyor-app/src/main.rs+10−13
@@ -1,23 +1,20 @@
1-//! The conveyor app: a view over conveyord. A blank canvas; Ctrl+click anywhere and write a
2-//! prompt, and the widget it asks for is built as a ticket and appears where you clicked.
3-mod acts;
4-mod canvas;
1+//! The conveyor app: it draws the user's widget library, starting from its `root` widget, and
2+//! the building tool over it: hold Ctrl, click any widget, and say what it should become.
3+mod app;
54 mod client;
6-mod live;
7-mod menu;
8-mod place;
9-mod prompt;
10-mod titlebar;
5+mod form;
6+mod inspect;
7+mod status;
118 mod widgets {
129 include!(concat!(env!("OUT_DIR"), "/widgets.rs"));
1310 }
1411
1512 use rune::{App, AppSpec, WindowOptions};
1613
17-/// The state frame buttons act on (see the library's api.rs).
18-pub type HostState = canvas::State;
14+/// The state every widget handler gets (see the library's api.rs).
15+pub type HostState = app::State;
1916
2017 fn main() {
21- let spec = AppSpec { setup: Some(canvas::setup), poll: Some(canvas::poll), ..AppSpec::new("Conveyor", (1400.0, 900.0), canvas::init, canvas::view) };
22- App::new(spec).window_options(WindowOptions { borderless: true, ..Default::default() }).run();
18+ let spec = AppSpec { setup: Some(app::setup), poll: Some(app::poll), ..AppSpec::new("Conveyor", (1400.0, 900.0), app::init, app::view) };
19+ App::new(spec).on_modifiers(app::on_modifiers).window_options(WindowOptions { borderless: true, ..Default::default() }).run();
2320 }
crates/conveyor-app/src/menu.rs+0−22
@@ -1,22 +0,0 @@
1-//! A widget's right-click menu: every frame control, even when its chrome is hidden or the
2-//! library's frame.rs has dropped a button.
3-use crate::{canvas::State, widgets::api::{Act, Chrome, Host}};
4-use rune::{El, Tx, col, row, text, tok};
5-
6-pub fn view(s: &State, id: u32, x: f32, y: f32) -> El {
7- let t = tok::theme(true);
8- let Some(p) = s.snap.canvas.iter().find(|p| p.id == id) else { return col() };
9- let item = |key: &str, label: String, a: Act| {
10- row().key(format!("menu-{key}")).w_full().h(30.0).center_y().px(12.0).radius(6.0).hover(t.hover).role("menuitem").label(label.clone())
11- .on_press_tx(move |s: &mut State, _: &mut Tx| s.act(id, a)).child(text(label).font(tok::type_::BODY).color(t.text))
12- };
13- let mark = |c: &str| if p.chrome == c { "● " } else { " " };
14- col().key("menu").role("menu").label("Widget").w(220.0).padding(6.0).radius(10.0).fill(t.card).border(1.0, t.hover).absolute(x, y)
15- .child(if p.maximized { item("restore", "Restore".into(), Act::Restore) } else { item("maximize", "Maximize".into(), Act::Maximize) })
16- .child(item("front", "Bring to front".into(), Act::Front))
17- .child(item("back", "Send to back".into(), Act::Back))
18- .child(item("notes", "Conversation".into(), Act::Notes))
19- .child(item("shown", format!("{}Title bar: always", mark("shown")), Act::Chrome(Chrome::Shown)))
20- .child(item("hover", format!("{}Title bar: on hover", mark("hover")), Act::Chrome(Chrome::Hover)))
21- .child(item("hidden", format!("{}Title bar: hidden", mark("hidden")), Act::Chrome(Chrome::Hidden)))
22-}
crates/conveyor-app/src/place.rs+0−47
@@ -1,47 +0,0 @@
1-//! One widget on the canvas: where it is, the frame around it, and what the pointer does to it.
2-//! Drag moves it, Ctrl+click follows up on it, right-click opens its menu.
3-use crate::{acts, canvas::State, client::{self, Placed}, live, prompt, widgets::{self, api::{Cx, Entry, Frame, TicketInfo}}};
4-use rune::{Drag, El, Phase, Tx, col, el, text, tok};
5-use serde_json::json;
6-
7-/// A widget no ticket has built yet: its prompt, in the frame.
8-const PENDING: (f32, f32) = (280.0, 120.0);
9-
10-pub fn view(s: &State, p: &Placed, tickets: &[TicketInfo], area: (f32, f32)) -> El {
11- let built = p.widget.as_deref().and_then(|w| widgets::ALL.iter().find(|(n, _)| *n == w)).map(|(_, w)| w);
12- let size = if p.maximized { area } else { built.map_or(PENDING, |w| w.size) };
13- let dir = live::dir(p.id);
14- let content = match s.widgets.get(&p.id) {
15- Some((_, w)) => w.view(&Cx { id: p.id, now: live::now(), tickets, dir: &dir }),
16- None => col().w_full().h_full().center().child(text(p.title.clone()).font(tok::type_::BODY).color(tok::theme(true).text).wrap()),
17- };
18- let thread: Vec<Entry> = p.thread.iter().map(|e| Entry { ticket: e.ticket, kind: e.kind.clone(), text: e.text.clone() }).collect();
19- let f = Frame { id: p.id, title: built.map_or("Building…", |w| w.title), size, state: &p.state, thread: &thread,
20- maximized: p.maximized, chrome: acts::chrome(&p.chrome), hovered: s.hovered == Some(p.id), notes: s.notes.contains(&p.id) };
21- let id = p.id;
22- let (x, y) = if p.maximized { (0.0, 0.0) } else { (p.x, p.y) };
23- el().key(format!("w-{id}")).label(format!("widget {}", f.title)).w(size.0).h(size.1).absolute(x, y)
24- .child(widgets::frame::frame(&f, content))
25- .on_drag(move |s: &mut State, d: &mut Drag, tx: &mut Tx| drag(s, id, d, tx))
26- .on_hover_change(move |s: &mut State, on: bool, _: &mut Tx| {
27- if on { s.hovered = Some(id) } else if s.hovered == Some(id) { s.hovered = None }
28- })
29- .on_secondary_press_local(move |s: &mut State, e: rune::PointerEvent, _: &mut Tx| s.menu = Some((id, x + e.x, y + e.y)))
30-}
31-
32-/// Moves a widget with the pointer, and tells conveyord where it landed.
33-/// Ctrl+press instead opens a prompt about the widget.
34-fn drag(s: &mut State, id: u32, d: &Drag, tx: &Tx) {
35- s.menu = None;
36- let Some(p) = s.snap.canvas.iter_mut().find(|p| p.id == id) else { return };
37- match (d.phase, s.drag) {
38- (Phase::Down, _) if tx.mods().ctrl => { let at = s.pointer; prompt::open(s, at, Some(id)) }
39- (Phase::Down, _) if !p.maximized => s.drag = Some((p.x, p.y)),
40- (Phase::Move, Some((x, y))) => (p.x, p.y) = ((x + d.dx).max(0.0), (y + d.dy).max(0.0)),
41- (Phase::Up, Some((x, y))) => {
42- s.drag = None;
43- if d.cancelled() { (p.x, p.y) = (x, y) } else { client::frame(id, json!({"x": p.x, "y": p.y})) }
44- }
45- _ => {}
46- }
47-}
crates/conveyor-app/src/prompt.rs+0−41
@@ -1,41 +0,0 @@
1-//! The Ctrl+click prompt: a new widget where you clicked, or a follow-up on the one you clicked.
2-use crate::{canvas::State, client};
3-use rune::{El, TextEdit, TextStyle, Tx, col, text, text_input, tok};
4-
5-pub fn open(s: &mut State, (x, y): (f32, f32), about: Option<u32>) {
6- s.menu = None;
7- s.prompt_at = Some((x, y, about));
8- s.prompt = TextEdit::new("");
9- s.prompt.focused = true;
10-}
11-
12-fn submit(s: &mut State, tx: &mut Tx) {
13- if let Some((x, y, about)) = s.prompt_at.take() {
14- let prompt = s.prompt.text.clone();
15- s.prompt = TextEdit::new("");
16- if !prompt.trim().is_empty() && client::widget(&prompt, x, y, about).is_none() {
17- eprintln!("conveyord isn't running; the prompt was not sent");
18- }
19- }
20- tx.blur();
21-}
22-
23-pub fn view(s: &State, x: f32, y: f32, about: Option<u32>) -> El {
24- let t = tok::theme(true);
25- let heading = match about.and_then(|a| s.snap.canvas.iter().find(|p| p.id == a)) {
26- Some(p) => format!("Follow up on {}", p.widget.clone().unwrap_or_else(|| format!("#{}", p.id))),
27- None => "New widget".into(),
28- };
29- col().key("prompt").w(360.0).h(120.0).radius(10.0).fill(t.card).padding(12.0).gap(6.0).absolute(x, y).focus_ring(2.0, 0.0, tok::accent(0, true))
30- .child(text(heading).font(tok::type_::LABEL).color(t.text_secondary))
31- .child(text_input(&s.prompt, TextStyle::new(14.0, 400.0)).key("prompt-input").label("Widget prompt").w_full().grow(1.0)
32- .padding(6.0).radius(6.0).fill(t.bg).color(t.text).placeholder("A clock with the date… Enter to send, Shift+Enter for a new line, Esc to cancel", t.text_secondary)
33- .on_edit(|s: &mut State| &mut s.prompt)
34- .on_submit(submit)
35- .on_input_key(|s: &mut State, e: &rune::KeyEvent, tx| {
36- if !matches!(e.key, rune::Key::Escape) { return false; }
37- s.prompt_at = None;
38- tx.blur();
39- true
40- }))
41-}
crates/conveyor-app/src/status.rs+49−0
@@ -0,0 +1,49 @@
1+//! Build status, bottom right: a pill per build in flight, and the agent's reply when one
2+//! finishes, until it's clicked away. Nothing of it stays on screen once read.
3+use crate::app::{State, save_ids};
4+use rune::{El, col, row, text, tok};
5+use serde_json::Value;
6+
7+const FINISHED: [&str; 3] = ["done", "failed", "parked"];
8+
9+fn pill(b: &Value, now: u64) -> El {
10+ let t = tok::theme(true);
11+ let secs = now.saturating_sub(b["since"].as_u64().unwrap_or(now));
12+ row().h(28.0).px(10.0).gap(8.0).center_y().radius(14.0).fill(t.card)
13+ .child(text(format!("#{} {}", b["id"], b["state"].as_str().unwrap_or(""))).font(tok::type_::LABEL).color(tok::accent(0, true)))
14+ .child(text(b["title"].as_str().unwrap_or("").to_owned()).font(tok::type_::LABEL).color(t.text))
15+ .child(text(format!("{}:{:02}", secs / 60, secs % 60)).font(tok::type_::LABEL).color(t.text_secondary))
16+}
17+
18+fn toast(b: &Value) -> El {
19+ let t = tok::theme(true);
20+ let id = b["id"].as_u64().unwrap_or(0);
21+ let last = b["thread"].as_array().into_iter().flatten().rev()
22+ .find(|e| matches!(e["kind"].as_str(), Some("reply" | "block" | "error" | "conveyor")));
23+ let said = last.and_then(|e| e["text"].as_str()).unwrap_or("").to_owned();
24+ let state = b["state"].as_str().unwrap_or("");
25+ let color = if state == "done" { tok::accent(0, true) } else { tok::accent(1, true) };
26+ col().key(format!("toast-{id}")).w(380.0).radius(10.0).fill(t.card).padding(12.0).gap(4.0).role("button").label("Dismiss")
27+ .border(1.0, color).hover(t.hover)
28+ .on_press_tx(move |s: &mut State, _| { s.seen.insert(id); save_ids(s.live.base(), "seen", &s.seen); })
29+ .child(text(format!("#{id} {state} · {}", b["kind"].as_str().unwrap_or(""))).font(tok::type_::LABEL).color(color))
30+ .child(text(said).color(t.text).w_full())
31+ .child(text(if state == "done" { "Click to dismiss" } else { "Ctrl+click the widget to follow up · click to dismiss" }).font(tok::type_::LABEL).color(t.text_secondary))
32+}
33+
34+pub fn view(s: &State) -> El {
35+ let t = tok::theme(true);
36+ let now = crate::widgets::api::now() as u64;
37+ let mut out = col().key("status").absolute(0.0, 0.0).w_full().h_full().padding(12.0).gap(8.0).items_end().justify_end();
38+ if !s.connected { out = out.child(text("conveyord isn't running").color(t.text_secondary)); }
39+ for b in s.snap["builds"].as_array().into_iter().flatten() {
40+ let state = b["state"].as_str().unwrap_or("");
41+ let id = b["id"].as_u64().unwrap_or(0);
42+ if FINISHED.contains(&state) {
43+ if !s.seen.contains(&id) { out = out.child(toast(b)); }
44+ } else if state != "draft" {
45+ out = out.child(pill(b, now));
46+ }
47+ }
48+ out
49+}
crates/conveyor-app/src/titlebar.rs+0−19
@@ -1,19 +0,0 @@
1-//! The app-drawn title bar: drag to move, double-click to maximize, and the window buttons.
2-use crate::canvas::State;
3-use rune::{El, el, row, text, tok};
4-
5-fn button(key: &'static str, label: &'static str, glyph: &'static str, f: impl Fn(&mut State, &mut rune::Tx) + 'static) -> El {
6- let t = tok::theme(true);
7- row().key(key).w(46.0).h_full().center().role("button").label(label).hover(t.hover).on_press_tx(f).child(text(glyph).color(t.text))
8-}
9-
10-pub fn bar(status: String) -> El {
11- let t = tok::theme(true);
12- row().key("titlebar").w_full().h(36.0).center_y().fill(t.card).window_drag().pl(14.0).gap(12.0)
13- .child(text("Conveyor").font(tok::type_::TITLE).color(t.text))
14- .child(text(status).font(tok::type_::BODY).color(t.text_secondary))
15- .child(el().grow(1.0))
16- .child(button("min", "Minimize", "_", |_, tx| tx.minimize()))
17- .child(button("max", "Maximize", "□", |_, tx| tx.toggle_maximized()))
18- .child(button("close", "Close", "×", |_, tx| tx.close_window()))
19-}
crates/conveyor/src/canvas.rs+0−77
@@ -1,77 +0,0 @@
1-//! Where widgets sit on the app's canvas, and how their frames are set: canvas.json.
2-use crate::paths;
3-use serde::{Deserialize, Serialize};
4-use serde_json::Value;
5-use std::{fs, sync::Mutex};
6-
7-static LOCK: Mutex<()> = Mutex::new(());
8-
9-#[derive(Serialize, Deserialize, Clone)]
10-pub struct Placed {
11- /// Stable for the widget's life: its first ticket.
12- pub id: u32,
13- /// Every ticket that built or changed it, oldest first. The last is current.
14- pub tickets: Vec<u32>,
15- pub x: f32,
16- pub y: f32,
17- /// Stacking order: higher draws on top.
18- #[serde(default)]
19- pub z: i32,
20- #[serde(default)]
21- pub maximized: bool,
22- /// The frame's chrome: "shown", "hover" or "hidden".
23- #[serde(default = "hover")]
24- pub chrome: String,
25- /// The widget's name in the library, once a ticket has built it.
26- pub widget: Option<String>,
27-}
28-
29-fn hover() -> String {
30- "hover".into()
31-}
32-
33-impl Placed {
34- pub fn current(&self) -> u32 {
35- *self.tickets.last().unwrap()
36- }
37-}
38-
39-pub fn load() -> Vec<Placed> {
40- fs::read_to_string(paths::canvas()).ok().and_then(|s| serde_json::from_str(&s).ok()).unwrap_or_default()
41-}
42-
43-fn update(f: impl FnOnce(&mut Vec<Placed>)) {
44- let _l = LOCK.lock().unwrap();
45- let mut all = load();
46- f(&mut all);
47- fs::write(paths::canvas(), serde_json::to_string_pretty(&all).unwrap()).unwrap();
48-}
49-
50-pub fn place(ticket: u32, x: f32, y: f32) {
51- update(|all| {
52- let z = all.iter().map(|p| p.z + 1).max().unwrap_or(0);
53- all.push(Placed { id: ticket, tickets: vec![ticket], x, y, z, maximized: false, chrome: hover(), widget: None })
54- });
55-}
56-
57-/// A follow-up ticket becomes the widget's current one.
58-pub fn follow(id: u32, ticket: u32) {
59- update(|all| all.iter_mut().filter(|p| p.id == id).for_each(|p| p.tickets.push(ticket)));
60-}
61-
62-pub fn set_widget(ticket: u32, widget: &str) {
63- update(|all| all.iter_mut().filter(|p| p.current() == ticket).for_each(|p| p.widget = Some(widget.into())));
64-}
65-
66-/// Merges the frame settings given (x, y, z, maximized, chrome) into one widget.
67-pub fn set_frame(id: u32, v: &Value) {
68- update(|all| {
69- for p in all.iter_mut().filter(|p| p.id == id) {
70- let mut j = serde_json::to_value(&*p).unwrap();
71- for k in ["x", "y", "z", "maximized", "chrome"] {
72- if !v[k].is_null() { j[k] = v[k].clone(); }
73- }
74- if let Ok(n) = serde_json::from_value(j) { *p = n; }
75- }
76- });
77-}
crates/conveyor/src/library.rs+78−48
@@ -1,7 +1,8 @@
1-//! The widget library: the `widgets` project. A prompt from the canvas becomes a ticket there;
2-//! a done ticket's change is merged into the library and the app is rebuilt with it.
3-use crate::{agent::git, canvas::{self, Placed}, paths, store::{self, Project}, thread, vm};
4-use serde_json::json;
1+//! The widget library: the `widgets` project. A Ctrl+click in the app becomes a build ticket
2+//! there, carrying what was clicked; a done ticket is merged and the app rebuilt with it.
3+use crate::{agent::git, paths, store::{self, Project}, thread, vm};
4+use serde::{Deserialize, Serialize};
5+use serde_json::{Value, json};
56 use std::{fs, process::Command, sync::Mutex};
67
78 pub const SLUG: &str = "widgets";
@@ -10,11 +11,30 @@ static BUILD: Mutex<()> = Mutex::new(());
1011 /// Conveyor's side of the library: kept in step with the template on every start.
1112 const OWNED: [&str; 8] = ["api.rs", "gen.rs", "CLAUDE.md", "Cargo.toml", "rust-toolchain.toml",
1213 "preview/Cargo.toml", "preview/build.rs", "preview/src/main.rs"];
13-/// The user's side: what a ticket may change.
14-const USERS: [&str; 2] = ["frame.rs", "widgets/"];
15-
1614 const COMMIT: [&str; 4] = ["-c", "user.name=conveyor", "-c", "user.email=conveyor@localhost"];
1715
16+/// What a build ticket was asked about, and what it changed: build.json beside ticket.md.
17+#[derive(Serialize, Deserialize, Default, Clone)]
18+pub struct Build {
19+ /// The kind (file name) of the widget clicked.
20+ pub kind: String,
21+ /// The instance clicked and then its parents, each with the point clicked in its own points.
22+ pub targets: Vec<(String, f32, f32)>,
23+ /// Widget kinds the merged branch added, and every kind it touched.
24+ #[serde(default)]
25+ pub created: Vec<String>,
26+ #[serde(default)]
27+ pub changed: Vec<String>,
28+}
29+
30+fn build(id: u32) -> Option<Build> {
31+ serde_json::from_str(&fs::read_to_string(store::dir(SLUG, id).join("build.json")).ok()?).ok()
32+}
33+
34+fn save_build(id: u32, b: &Build) {
35+ let _ = fs::write(store::dir(SLUG, id).join("build.json"), serde_json::to_string_pretty(b).unwrap());
36+}
37+
1838 /// Creates the library from conveyor's template on first run, and updates conveyor's files in it.
1939 pub fn ensure() -> Result<(), String> {
2040 let (lib, tpl) = (paths::library(), paths::source().join("templates/library"));
@@ -35,46 +55,56 @@ pub fn ensure() -> Result<(), String> {
3555 Ok(())
3656 }
3757
38-/// A prompt written on the canvas at (x, y): a ready ticket, and a placeholder where it was clicked.
39-/// With `about`, the user Ctrl+clicked that widget: the new ticket follows up on it.
40-pub fn request(prompt: &str, x: f32, y: f32, about: Option<u32>) -> u32 {
41- let title: String = prompt.lines().next().unwrap_or("widget").chars().take(70).collect();
42- let placed = about.and_then(|a| canvas::load().into_iter().find(|p| p.id == a));
43- let context = match &placed {
44- Some(p) => follow_up(p, x - p.x, y - p.y),
45- None => format!("The user asked for this widget by clicking at ({x:.0}, {y:.0}) on the canvas."),
46- };
47- let id = store::create(SLUG, &title, &format!("{prompt}\n\n---\n\n{context}"), "ready");
48- match placed {
49- Some(p) => canvas::follow(p.id, id),
50- None => canvas::place(id, x, y),
51- }
52- id
58+/// Tickets about a widget kind, oldest first: asked from it, or that changed it.
59+fn about(kind: &str) -> Vec<u32> {
60+ store::tickets(SLUG).iter().filter(|t| build(t.id).is_some_and(|b| b.kind == kind || b.changed.iter().any(|c| c == kind))).map(|t| t.id).collect()
5361 }
5462
55-/// What the user clicked, and the conversation behind it so far.
56-fn follow_up(p: &Placed, x: f32, y: f32) -> String {
57- let what = match &p.widget {
58- Some(w) => format!("The user Ctrl+clicked the `{w}` widget, at ({x:.0}, {y:.0}) inside it. Change `widgets/{w}.rs` and keep its name."),
59- None => "The user Ctrl+clicked a widget that no ticket has built yet. Build what the conversation asks for.".into(),
60- };
61- let history: String = thread::of(&p.tickets).iter()
63+/// A Ctrl+click: the prompt, and everything the app knew about what was under the pointer.
64+pub fn request(r: &Value) -> u32 {
65+ let s = |k: &str| r[k].as_str().unwrap_or("").trim().to_owned();
66+ let (prompt, kind) = (s("prompt"), if s("kind").is_empty() { "root".into() } else { s("kind") });
67+ let targets: Vec<(String, f32, f32)> = serde_json::from_value(r["targets"].clone()).unwrap_or_default();
68+ let (target, x, y) = targets.first().cloned().unwrap_or(("root".into(), 0.0, 0.0));
69+ let parents: String = targets.iter().skip(1).map(|t| format!("`{}`", t.0)).collect::<Vec<_>>().join(", ");
70+ let history: String = thread::of(&about(&kind)).iter()
6271 .map(|e| format!("- #{} {}: {}\n", e["ticket"], e["kind"].as_str().unwrap_or(""), e["text"].as_str().unwrap_or("").replace('\n', "\n ")))
6372 .collect();
64- format!("{what}\n\nThe conversation so far, oldest first:\n\n{history}")
73+ let context = format!(
74+ "The user Ctrl+clicked the `{kind}` widget (`widgets/{kind}.rs`), instance `{target}`, at ({x:.0}, {y:.0}) inside it.\n\
75+ Its parents, innermost first: {parents}\n\
76+ The element under the pointer: `{element}`\n\n\
77+ The widgets on screen, as instance (kind):\n\n{tree}\n\n\
78+ Shared values: {shared}\n\n\
79+ The conversation about `{kind}` so far, oldest first:\n\n{history}",
80+ parents = if parents.is_empty() { "none".into() } else { parents }, element = s("element"), tree = s("tree"),
81+ shared = if s("shared").is_empty() { "none".into() } else { s("shared") },
82+ history = if history.is_empty() { "- none yet\n".into() } else { history });
83+ let title: String = prompt.lines().next().unwrap_or("widget").chars().take(70).collect();
84+ let id = store::create(SLUG, &title, &format!("{prompt}\n\n---\n\n{context}"), "ready");
85+ save_build(id, &Build { kind, targets, ..Default::default() });
86+ id
6587 }
6688
67-/// Merges a done widget ticket into the library, then rebuilds the app with it.
89+/// Merges a done build ticket into the library, then rebuilds the app with it.
6890 pub fn install(p: &Project, id: u32, branch: &str) -> Result<(), String> {
69- let changed = git(&p.path, "", &["diff", "--name-only", &format!("main...{branch}")])?;
70- if let Some(f) = changed.lines().find(|f| !USERS.iter().any(|u| f.starts_with(u))) {
71- return Err(format!("the branch changes {f}, which is conveyor's; only frame.rs and widgets/ are the library's"));
91+ let range = format!("main...{branch}");
92+ let changed = git(&p.path, "", &["diff", "--name-only", &range])?;
93+ if let Some(f) = changed.lines().find(|f| !f.starts_with("widgets/")) {
94+ return Err(format!("the branch changes {f}, which is conveyor's; only widgets/ is the library's"));
7295 }
73- let widget = changed.lines().find_map(|f| f.strip_prefix("widgets/")?.strip_suffix(".rs")).map(String::from);
96+ let kinds = |list: String| list.lines().filter_map(|f| f.strip_prefix("widgets/")?.strip_suffix(".rs").map(String::from)).collect::<Vec<_>>();
97+ let created = kinds(git(&p.path, "", &["diff", "--name-only", "--diff-filter=A", &range])?);
7498 git(&p.path, "", &[&COMMIT[..], &["merge", "-q", "--no-edit", branch]].concat())?;
7599 store::event(SLUG, id, json!({"kind": "conveyor", "msg": "merged; rebuilding the app"}));
76- rebuild_app()?;
77- if let Some(w) = widget { canvas::set_widget(id, &w); }
100+ // A library that doesn't build never stays on main: the app could not restart into it.
101+ if let Err(e) = rebuild_app() {
102+ git(&p.path, "", &["reset", "-q", "--hard", "ORIG_HEAD"])?;
103+ return Err(format!("the app doesn't build with this branch, so it was not merged:\n{e}"));
104+ }
105+ let mut b = build(id).unwrap_or_default();
106+ (b.created, b.changed) = (created, kinds(changed));
107+ save_build(id, &b);
78108 Ok(())
79109 }
80110
@@ -85,16 +115,16 @@ fn rebuild_app() -> Result<(), String> {
85115 .args(["build", "--release", "-q", "-p", "conveyor-app"])).map(|_| ())
86116 }
87117
88-/// Everything the app shows: tickets, and each widget with its frame and its thread.
89-pub fn snapshot() -> serde_json::Value {
90- let tickets: Vec<_> = store::projects().iter().flat_map(|p| store::tickets(&p.slug)).collect();
91- let canvas: Vec<_> = canvas::load().into_iter().map(|p| {
92- let t = store::ticket(SLUG, p.current());
93- let mut v = serde_json::to_value(&p).unwrap();
94- v["state"] = json!(t.as_ref().map_or("", |t| t.state.as_str()));
95- v["title"] = json!(t.as_ref().map_or("", |t| t.title.as_str()));
96- v["thread"] = json!(thread::of(&p.tickets));
97- v
118+/// Everything the app shows: projects, tickets, recent activity, and each build with its thread.
119+pub fn snapshot() -> Value {
120+ let projects = store::projects();
121+ let tickets: Vec<_> = projects.iter().flat_map(|p| store::tickets(&p.slug)).collect();
122+ let builds: Vec<_> = store::tickets(SLUG).into_iter().filter_map(|t| {
123+ let b = build(t.id)?;
124+ let finished = store::events(SLUG, t.id).iter().rev().find(|e| e["kind"] == "state").and_then(|e| e["at"].as_u64()).unwrap_or(0);
125+ Some(json!({"id": t.id, "title": t.title, "state": t.state, "kind": b.kind, "targets": b.targets,
126+ "created": b.created, "changed": b.changed, "since": finished, "thread": thread::of(&[t.id])}))
98127 }).collect();
99- json!({"tickets": tickets, "canvas": canvas})
128+ let projects: Vec<_> = projects.iter().map(|p| json!({"slug": p.slug, "path": p.path, "slots": p.slots})).collect();
129+ json!({"projects": projects, "tickets": tickets, "activity": store::activity(), "builds": builds})
100130 }
crates/conveyor/src/main.rs+1−1
@@ -1,6 +1,5 @@
11 //! conveyor: the daemon, its CLI, and (inside a ticket's VM) the agent's verbs. One binary.
22 mod agent;
3-mod canvas;
43 mod dispatch;
54 mod library;
65 mod paths;
@@ -27,6 +26,7 @@ fn main() {
2726 let code = match a(0) {
2827 "daemon" => {
2928 library::ensure().expect("create the widget library");
29+ store::load_activity();
3030 std::thread::spawn(|| dispatch::run());
3131 server::serve();
3232 0
crates/conveyor/src/paths.rs+0−4
@@ -18,10 +18,6 @@ pub fn library() -> PathBuf {
1818 data().join("library")
1919 }
2020
21-pub fn canvas() -> PathBuf {
22- data().join("canvas.json")
23-}
24-
2521 pub fn base_image() -> PathBuf {
2622 data().join("images/base.qcow2")
2723 }
crates/conveyor/src/server.rs+13−13
@@ -1,10 +1,10 @@
1-//! The socket the app and the CLI use: one JSON request per line, one JSON reply per line.
2-//! {"op":"state"} tickets and canvas
3-//! {"op":"widget","prompt":"…","x":10,"y":20} a widget ticket, placed on the canvas
4-//! + "about":3 …or a follow-up on the widget ticket #3 placed
Cut short: this commit's diff is over 1000 lines.
crates/conveyor/src/store.rs+29−1
Cut short: this commit's diff is over 1000 lines.
templates/library/CLAUDE.md+33−24
Cut short: this commit's diff is over 1000 lines.
templates/library/api.rs+254−76
Cut short: this commit's diff is over 1000 lines.
templates/library/frame.rs+0−80
Cut short: this commit's diff is over 1000 lines.
templates/library/gen.rs+3−4
Cut short: this commit's diff is over 1000 lines.
templates/library/preview/src/main.rs+61−59
Cut short: this commit's diff is over 1000 lines.
templates/library/widgets/canvas.rs+83−0
Cut short: this commit's diff is over 1000 lines.
templates/library/widgets/root.rs+16−0
Cut short: this commit's diff is over 1000 lines.
templates/library/widgets/titlebar.rs+24−0
Cut short: this commit's diff is over 1000 lines.