xonecas.io
8447
Co

conveyor / commit bf4eba8

Canvas: drag widgets, Escape cancels, restart that survives a rebuild

Escape goes through on_input_key, since a focused field keeps its keys.
The app reads its own path once at launch: after cargo replaces the
binary, current_exe() points at the deleted file and the restart never
fired. Widget prompts that ask for nothing now block instead of
building a stand-in.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-09 bf4eba850cd5316e1e85064a39a301563f21c232 parent 8e63224

6 files changed

DESIGN.md+3−0
@@ -194,6 +194,9 @@ Ctrl+click (x,y) ─▶ prompt ─▶ conveyord: widgets ticket #n (ready) + can
194194 ```
195195
196196 - Until the widget is built, the canvas shows a card with the ticket's state at the spot you clicked.
197+- Drag a widget to move it. The app sends the drop to conveyord (`move`), which writes `canvas.json`.
198+- A prompt that asks for nothing, such as a keyboard mash, is a `block`: the card turns red and you rewrite it. An agent that guesses fills your library with stand-ins.
199+- The app restarts with `exec` on the path it read at launch. After cargo replaces the binary, `current_exe()` names the deleted file, so it can't be read again later.
197200 - The library API is deliberately small (`api.rs`): a widget is a title, a size and `fn view(&Cx) -> El`. `Cx` holds the time and the tickets. Widgets display only, and may use `rune` and `std` only.
198201 - `gen.rs` turns `widgets/*.rs` into `#[path]` modules and `ALL`. The app's `build.rs` and the library's own `preview` crate both include it, so the agent verifies with exactly the code the app compiles.
199202 - The base image carries the pinned toolchain and a warm `~/.cache/conveyor-target`, so the agent's first preview build is incremental.
crates/conveyor-app/src/canvas.rs+36−13
@@ -1,8 +1,8 @@
11 //! The canvas: widgets where they were asked for, a card for each widget still being built,
22 //! and the Ctrl+click prompt that asks for a new one.
33 use crate::{client::{self, Snapshot}, titlebar, widgets};
4-use rune::{El, TextEdit, TextStyle, Tx, Waker, col, el, text, text_input, tok};
5-use std::{sync::{Arc, Mutex}, time::{Duration, SystemTime, UNIX_EPOCH}};
4+use rune::{Drag, El, Phase, TextEdit, TextStyle, Tx, Waker, col, el, text, text_input, tok};
5+use std::{path::{Path, PathBuf}, sync::{Arc, Mutex}, time::{Duration, SystemTime, UNIX_EPOCH}};
66
77 pub struct State {
88 snap: Snapshot,
@@ -11,19 +11,26 @@ pub struct State {
1111 prompt_at: Option<(f32, f32)>,
1212 prompt: TextEdit,
1313 inbox: Arc<Mutex<Option<Option<Snapshot>>>>,
14+ /// The binary at launch and its mtime. Read once: after cargo replaces it,
15+ /// current_exe() names the deleted file.
16+ exe: Option<PathBuf>,
1417 built: Option<SystemTime>,
18+ /// A widget's position when the drag on it started.
19+ drag: Option<(f32, f32)>,
1520 }
1621
17-fn exe_time() -> Option<SystemTime> {
18- std::fs::metadata(std::env::current_exe().ok()?).ok()?.modified().ok()
22+fn mtime(p: &Path) -> Option<SystemTime> {
23+ std::fs::metadata(p).ok()?.modified().ok()
1924 }
2025
2126 pub fn init() -> State {
22- State { snap: Snapshot::default(), connected: false, pointer: (0.0, 0.0), prompt_at: None, prompt: TextEdit::new(""), inbox: Default::default(), built: exe_time() }
27+ State { snap: Snapshot::default(), connected: false, pointer: (0.0, 0.0), prompt_at: None, prompt: TextEdit::new(""), inbox: Default::default(), exe: None, built: None, drag: None }
2328 }
2429
2530 /// Polls conveyord once a second on a thread. Every poll also re-renders, for clocks.
2631 pub fn setup(s: &mut State, waker: Waker) {
32+ s.exe = std::env::current_exe().ok();
33+ s.built = s.exe.as_deref().and_then(mtime);
2734 let inbox = s.inbox.clone();
2835 std::thread::spawn(move || loop {
2936 *inbox.lock().unwrap() = Some(client::state());
@@ -35,13 +42,14 @@ pub fn setup(s: &mut State, waker: Waker) {
3542 pub fn poll(s: &mut State, _t: f64, _tx: &mut Tx) -> bool {
3643 let Some(snap) = s.inbox.lock().unwrap().take() else { return false };
3744 s.connected = snap.is_some();
38- if let Some(snap) = snap { s.snap = snap; }
45+ // Mid-drag, the daemon's copy would snap the widget back.
46+ if let Some(snap) = snap && s.drag.is_none() { s.snap = snap; }
3947 // conveyord rebuilt the app with a new widget: become the new binary, in place.
40- if exe_time() != s.built {
48+ if let Some(exe) = &s.exe && let Some(t) = mtime(exe) && Some(t) != s.built {
4149 use std::os::unix::process::CommandExt;
42- let err = std::process::Command::new(std::env::current_exe().unwrap()).args(std::env::args().skip(1)).exec();
50+ let err = std::process::Command::new(exe).args(std::env::args().skip(1)).exec();
4351 eprintln!("restart failed: {err}");
44- s.built = exe_time();
52+ s.built = Some(t);
4553 }
4654 true
4755 }
@@ -57,6 +65,20 @@ fn submit(s: &mut State, tx: &mut Tx) {
5765 tx.blur();
5866 }
5967
68+/// Moves a widget with the pointer, and tells conveyord where it landed.
69+fn drag(s: &mut State, id: u32, d: &Drag) {
70+ let Some(p) = s.snap.canvas.iter_mut().find(|p| p.ticket == id) else { return };
71+ match (d.phase, s.drag) {
72+ (Phase::Down, _) => s.drag = Some((p.x, p.y)),
73+ (Phase::Move, Some((x, y))) => (p.x, p.y) = ((x + d.dx).max(0.0), (y + d.dy).max(0.0)),
74+ (Phase::Up, Some((x, y))) => {
75+ s.drag = None;
76+ if d.cancelled() { (p.x, p.y) = (x, y) } else { client::move_to(id, p.x, p.y); }
77+ }
78+ _ => {}
79+ }
80+}
81+
6082 fn card(key: String, w: f32, h: f32) -> El {
6183 let t = tok::theme(true);
6284 col().key(key).w(w).h(h).radius(10.0).fill(t.card).padding(12.0).gap(6.0)
@@ -81,7 +103,8 @@ fn placed(s: &State, cx: &widgets::api::Cx) -> Vec<El> {
81103 pending(p.ticket, t.map_or("", |t| t.title.as_str()), state)
82104 }
83105 };
84- el.absolute(p.x, p.y)
106+ let id = p.ticket;
107+ el.absolute(p.x, p.y).on_drag(move |s: &mut State, d: &mut Drag, _: &mut Tx| drag(s, id, d))
85108 }).collect()
86109 }
87110
@@ -90,10 +113,10 @@ fn prompt_box(s: &State, x: f32, y: f32) -> El {
90113 card("prompt".into(), 360.0, 120.0).absolute(x, y).focus_ring(2.0, 0.0, tok::accent(0, true))
91114 .child(text("New widget").font(tok::type_::LABEL).color(t.text_secondary))
92115 .child(text_input(&s.prompt, TextStyle::new(14.0, 400.0)).key("prompt-input").label("Widget prompt").w_full().grow(1.0)
93- .padding(6.0).radius(6.0).fill(t.bg).color(t.text).placeholder("A clock with the date… Enter to build, Esc to cancel", t.text_secondary)
116+ .padding(6.0).radius(6.0).fill(t.bg).color(t.text).placeholder("A clock with the date… Enter to build, Shift+Enter for a new line, Esc to cancel", t.text_secondary)
94117 .on_edit(|s: &mut State| &mut s.prompt)
95118 .on_submit(submit)
96- .on_key(|s: &mut State, e: &rune::KeyEvent, tx| {
119+ .on_input_key(|s: &mut State, e: &rune::KeyEvent, tx| {
97120 if !matches!(e.key, rune::Key::Escape) { return false; }
98121 s.prompt_at = None;
99122 tx.blur();
@@ -122,6 +145,6 @@ pub fn view(s: &State, _: &mut rune::Cx<State>) -> El {
122145 }
123146 for e in placed(s, &cx) { canvas = canvas.child(e); }
124147 if let Some((x, y)) = s.prompt_at { canvas = canvas.child(prompt_box(s, x, y)); }
125- let status = if s.connected { format!("{} widgets", widgets::ALL.len()) } else { "conveyord isn't running".into() };
148+ let status = if s.connected { String::new() } else { "conveyord isn't running".into() };
126149 col().key("root").w_full().h_full().fill(t.bg).child(titlebar::bar(status)).child(canvas)
127150 }
crates/conveyor-app/src/client.rs+4−0
@@ -41,3 +41,7 @@ pub fn state() -> Option<Snapshot> {
4141 pub fn widget(prompt: &str, x: f32, y: f32) -> Option<u32> {
4242 call(json!({"op": "widget", "prompt": prompt, "x": x, "y": y}))?["id"].as_u64().map(|id| id as u32)
4343 }
44+
45+pub fn move_to(ticket: u32, x: f32, y: f32) {
46+ call(json!({"op": "move", "ticket": ticket, "x": x, "y": y}));
47+}
crates/conveyor/src/canvas.rs+4−0
@@ -32,3 +32,7 @@ pub fn place(p: Placed) {
3232 pub fn set_widget(ticket: u32, widget: &str) {
3333 update(|all| all.iter_mut().filter(|p| p.ticket == ticket).for_each(|p| p.widget = Some(widget.into())));
3434 }
35+
36+pub fn move_to(ticket: u32, x: f32, y: f32) {
37+ update(|all| all.iter_mut().filter(|p| p.ticket == ticket).for_each(|p| (p.x, p.y) = (x, y)));
38+}
crates/conveyor/src/server.rs+7−1
@@ -1,8 +1,9 @@
11 //! The socket the app and the CLI use: one JSON request per line, one JSON reply per line.
22 //! {"op":"state"} tickets and canvas
33 //! {"op":"widget","prompt":"…","x":10,"y":20} a widget ticket, placed on the canvas
4+//! {"op":"move","ticket":1,"x":10,"y":20} a widget dragged on the canvas
45 //! {"op":"ticket","project":"…","title":"…","body":"…"}
5-use crate::{library, paths, store};
6+use crate::{canvas, library, paths, store};
67 use serde_json::{Value, json};
78 use std::{io::{BufRead, BufReader, Write}, os::unix::net::{UnixListener, UnixStream}};
89
@@ -31,6 +32,11 @@ fn handle(r: &Value) -> Value {
3132 "widget" if !s("prompt").trim().is_empty() => {
3233 json!({"id": library::request(s("prompt").trim(), r["x"].as_f64().unwrap_or(0.0) as f32, r["y"].as_f64().unwrap_or(0.0) as f32)})
3334 }
35+ "move" => {
36+ let f = |k: &str| r[k].as_f64().unwrap_or(0.0) as f32;
37+ canvas::move_to(r["ticket"].as_u64().unwrap_or(0) as u32, f("x"), f("y"));
38+ json!({"ok": true})
39+ }
3440 "ticket" if store::project(s("project")).is_some() => json!({"id": store::create(s("project"), s("title"), s("body"), "ready")}),
3541 _ => json!({"error": "bad request"}),
3642 }
templates/library/CLAUDE.md+4−0
@@ -2,6 +2,10 @@
22
33 This repo is the user's widget library. Each ticket asks for one widget, in the user's own words. The conveyor app shows the widget on the user's canvas, at the spot they clicked.
44
5+## If it isn't a widget request
6+
7+If the ticket's words don't describe something to show, such as a keyboard mash or a stray word, don't guess a widget. Run `conveyor block --reason "<what's unclear>" --recommend "<what you'd build if they meant something>"` and stop. The card turns red on the user's canvas, and the user rewrites the prompt.
8+
59 ## Make the widget
610
711 1. Pick a short snake_case name, such as `clock` or `parked_tickets`. It must be a valid Rust identifier and must not clash with a file in `widgets/`.