xonecas.io
8447
Co

conveyor / commit 10cc698

Ponytail pass: serde over hand-rolled formats, drop dead code

- api.rs: requests are json!, and the preview's data is data.json via
  serde derives, replacing quote() and a TSV codec (serde and serde_json
  were already in the library's lockfile through rune-kit). shared_line
  had no callers.
- safe.rs uses Live::keep_build instead of its own request.
- auto_merge could never be set, and merging is the user's: gone.
- `conveyor project` and `retry` go through the server, so the CLI gets
  its validation; retry's note is written only once the move is taken.
- bake.py keeps only `bake`: the spike's up/down/ls/ssh/snap/restore
  live on in spikes/1-vm/vm.py.

The preview's new serde features change the warm cache: the base image
was rebaked with them.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-09 10cc6985a05ebb1789cce984e8c444acbb84d2d9 parent 3c10db6

11 files changed

crates/conveyor-app/src/safe.rs+4−4
@@ -2,7 +2,7 @@
22 //! (root or status panicked, or the user asked from the Ctrl inspector, or `--safe`). It lists the
33 //! builds on trial with Keep and Discard, and leaving it makes every widget again.
44 //! The shared value `safe_mode = off` stops offering it; `--safe` still opens it.
5-use crate::{app::State, client};
5+use crate::app::State;
66 use rune::{El, col, el, row, text, tok};
77
88 /// Whether the inspector offers it and a broken root or status opens it.
@@ -31,11 +31,11 @@ pub fn view(s: &State, why: &str) -> El {
3131 if trial.is_empty() { list = list.child(text("No builds on trial.").color(t.text_secondary)); }
3232 for b in trial {
3333 let id = b["id"].as_u64().unwrap_or(0);
34- let send = move |op: &'static str| move |_: &mut State| client::send(format!("{{\"op\":\"{op}\",\"id\":{id}}}"));
34+ let decide = move |keep: bool| move |s: &mut State| s.live.keep_build(id as u32, keep);
3535 list = list.child(row().key(format!("build-{id}")).w_full().gap(8.0).center_y()
3636 .child(text(format!("#{id} {}", b["title"].as_str().unwrap_or(""))).color(t.text).grow(1.0).min_w(0.0).truncate())
37- .child(button(format!("discard-{id}"), "Discard", t.hover, t.text, send("discard")))
38- .child(button(format!("keep-{id}"), "Keep", tok::accent(0, true), t.bg, send("keep"))));
37+ .child(button(format!("discard-{id}"), "Discard", t.hover, t.text, decide(false)))
38+ .child(button(format!("keep-{id}"), "Keep", tok::accent(0, true), t.bg, decide(true))));
3939 }
4040 let offer = offered(s);
4141 let card = col().key("safe").w(560.0).padding(24.0).gap(12.0).radius(10.0).fill(t.card)
crates/conveyor/src/agent.rs+1−2
@@ -69,8 +69,7 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
6969 Outcome::Blocked => "parked".into(),
7070 Outcome::None => "failed".into(),
7171 Outcome::Done(_) if p.library => { library::try_out(p, id, &branch)?; "review".into() }
72- Outcome::Done(_) if !p.auto_merge => "review".into(),
73- Outcome::Done(_) => { git(&p.path, "", &["merge", "-q", "--no-edit", &branch])?; "done".into() }
72+ Outcome::Done(_) => "review".into(),
7473 })
7574 }
7675
crates/conveyor/src/library.rs+1−1
@@ -60,7 +60,7 @@ pub fn ensure() -> Result<(), String> {
6060 git(&lib, "", &[&COMMIT[..], &["commit", "-qm", "Conveyor's library files"]].concat())?;
6161 }
6262 if store::project(SLUG).is_none() {
63- store::save_project(&Project { slug: SLUG.into(), path: lib, slots: 2, auto_merge: false, library: true });
63+ store::save_project(&Project { slug: SLUG.into(), path: lib, slots: 2, library: true });
6464 }
6565 // main may have moved (conveyor's files above): the trial and the app follow it.
6666 std::thread::spawn(|| if let Err(e) = trial(None) { eprintln!("library trial: {e}") });
crates/conveyor/src/main.rs+9−6
@@ -33,9 +33,10 @@ fn main() {
3333 0
3434 }
3535 "project" if !a(2).is_empty() => {
36- let path = std::fs::canonicalize(a(2)).expect("project path");
37- store::save_project(&store::Project { slug: a(1).into(), path, slots: a(3).parse().unwrap_or(1), auto_merge: false, library: false });
38- 0
36+ let path = std::path::absolute(a(2)).expect("project path");
37+ let mut req = json!({"op": "project", "slug": a(1), "path": path});
38+ if let Ok(n) = a(3).parse::<u32>() { req["slots"] = json!(n); }
39+ print(server::call(req))
3940 }
4041 "ticket" if !a(2).is_empty() => print(server::call(json!({"op": "ticket", "project": a(1), "title": a(2), "body": a(3)}))),
4142 "call" if !a(1).is_empty() => match serde_json::from_str(a(1)) {
@@ -44,9 +45,11 @@ fn main() {
4445 },
4546 "retry" if a(2).parse::<u32>().is_ok() => {
4647 let id = a(2).parse().unwrap();
47- if !a(3).is_empty() { store::event(a(1), id, serde_json::json!({"kind": "conveyor", "msg": a(3), "show": true})); }
48- store::set_state(a(1), id, "ready");
49- 0
48+ let r = server::call(json!({"op": "set", "project": a(1), "id": id, "state": "ready"}));
49+ if !a(3).is_empty() && r.as_ref().is_ok_and(|v| v["ok"] == true) {
50+ store::event(a(1), id, json!({"kind": "conveyor", "msg": a(3), "show": true}));
51+ }
52+ print(r)
5053 }
5154 "ls" => {
5255 for p in store::projects() {
crates/conveyor/src/server.rs+1−1
@@ -85,7 +85,7 @@ fn project(slug: &str, r: &Value) -> Result<Value, String> {
8585 crate::agent::git(&path, "", &["init", "-q", "-b", "main"])?;
8686 crate::agent::git(&path, "", &["-c", "user.name=conveyor", "-c", "user.email=conveyor@localhost", "commit", "-q", "--allow-empty", "-m", "Start"])?;
8787 }
88- store::Project { slug: slug.into(), path, slots: 1, auto_merge: false, library: false }
88+ store::Project { slug: slug.into(), path, slots: 1, library: false }
8989 }
9090 (None, None) => return Err(format!("no project {slug}")),
9191 };
crates/conveyor/src/store.rs+0−3
@@ -16,9 +16,6 @@ pub struct Project {
1616 pub path: PathBuf,
1717 #[serde(default = "one")]
1818 pub slots: usize,
19- /// Merge a finished branch into main without review.
20- #[serde(default)]
21- pub auto_merge: bool,
2219 /// This project is the widget library.
2320 #[serde(default)]
2421 pub library: bool,
templates/library/Cargo.lock+2−0
@@ -2351,6 +2351,8 @@ version = "0.0.0"
23512351 dependencies = [
23522352 "rune",
23532353 "rune-kit",
2354+ "serde",
2355+ "serde_json",
23542356 ]
23552357
23562358 [[package]]
templates/library/api.rs+14−85
@@ -2,11 +2,13 @@
22 //! when it changes. Everything in widgets/ is the library's, starting with root.rs: the app
33 //! draws `root` and nothing else, so the whole UI is widgets.
44 use rune::{El, TextEdit, Tx, col};
5+use serde::{Deserialize, Serialize};
6+use serde_json::json;
57 use std::{any::Any, cell::{Cell, OnceCell, RefCell}, rc::Rc, collections::{BTreeMap, BTreeSet, HashMap}, path::{Path, PathBuf}};
68
79 // ── What widgets read: conveyor's state ─────────────────────────────────────────────────────
810
9-#[derive(Clone, Default, Debug)]
11+#[derive(Clone, Default, Debug, Serialize, Deserialize)]
1012 pub struct Project {
1113 pub slug: String,
1214 pub path: String,
@@ -14,7 +16,7 @@ pub struct Project {
1416 pub slots: u32,
1517 }
1618
17-#[derive(Clone, Default, Debug)]
19+#[derive(Clone, Default, Debug, Serialize, Deserialize)]
1820 pub struct Ticket {
1921 pub project: String,
2022 pub id: u32,
@@ -35,7 +37,7 @@ pub struct Ticket {
3537
3638 /// One thing that happened to a ticket: a state change, an agent's note, decision, deviation,
3739 /// block or reply, or conveyor's own step.
38-#[derive(Clone, Default, Debug)]
40+#[derive(Clone, Default, Debug, Serialize, Deserialize)]
3941 pub struct Activity {
4042 /// Unix seconds.
4143 pub at: u64,
@@ -46,7 +48,7 @@ pub struct Activity {
4648 pub text: String,
4749 }
4850
49-#[derive(Default)]
51+#[derive(Default, Serialize, Deserialize)]
5052 pub struct Data {
5153 pub projects: Vec<Project>,
5254 pub tickets: Vec<Ticket>,
@@ -253,22 +255,6 @@ pub fn keep_build(h: &mut HostState, id: u32, keep: bool) {
253255 Host::live(h).keep_build(id, keep)
254256 }
255257
256-/// A JSON string literal.
257-pub fn quote(s: &str) -> String {
258- let mut out = String::from("\"");
259- for c in s.chars() {
260- match c {
261- '"' => out.push_str("\\\""),
262- '\\' => out.push_str("\\\\"),
263- '\n' => out.push_str("\\n"),
264- c if (c as u32) < 0x20 => out.push_str(&format!("\\u{:04x}", c as u32)),
265- c => out.push(c),
266- }
267- }
268- out.push('"');
269- out
270-}
271-
272258 // ── The host's side: conveyor's app and the preview drive this; widgets never need to ───────
273259
274260 /// Every widget instance, what they share, and what they asked of the host.
@@ -317,15 +303,13 @@ impl Live {
317303 if let Some(t) = self.data.tickets.iter_mut().find(|t| t.project == project && t.id == id && t.state != "running") {
318304 (t.state, t.since) = (state.to_owned(), now() as u64);
319305 }
320- self.call(format!("{{\"op\":\"set\",\"project\":{},\"id\":{id},\"state\":{}}}", quote(project), quote(state)));
306+ self.call(json!({"op": "set", "project": project, "id": id, "state": state}).to_string());
321307 }
322308
323309 /// Writes a ticket. `files` are copied into it, and the agent working it gets them.
324310 /// `ready` starts an agent on it as soon as a slot is free.
325311 pub fn new_ticket(&mut self, project: &str, title: &str, body: &str, state: &str, files: &[PathBuf]) {
326- let files: Vec<String> = files.iter().map(|f| quote(&f.to_string_lossy())).collect();
327- self.call(format!("{{\"op\":\"ticket\",\"project\":{},\"title\":{},\"body\":{},\"state\":{},\"files\":[{}]}}",
328- quote(project), quote(title), quote(body), quote(state), files.join(",")));
312+ self.call(json!({"op": "ticket", "project": project, "title": title, "body": body, "state": state, "files": files}).to_string());
329313 }
330314
331315 /// Rewrites a ticket's title and body, in place. Shown at once. Conveyor refuses it while
@@ -334,13 +318,13 @@ impl Live {
334318 if let Some(t) = self.data.tickets.iter_mut().find(|t| t.project == project && t.id == id && t.state != "running") {
335319 (t.title, t.body) = (title.to_owned(), body.to_owned());
336320 }
337- self.call(format!("{{\"op\":\"edit\",\"project\":{},\"id\":{id},\"title\":{},\"body\":{}}}", quote(project), quote(title), quote(body)));
321+ self.call(json!({"op": "edit", "project": project, "id": id, "title": title, "body": body}).to_string());
338322 }
339323
340324 /// Adds a project: `slug` names it, `path` is its folder: a git repo, or a new or empty
341325 /// folder that becomes one. Pick a folder with `tx.open_folder(...)`.
342326 pub fn add_project(&mut self, slug: &str, path: &Path) {
343- self.call(format!("{{\"op\":\"project\",\"slug\":{},\"path\":{}}}", quote(slug), quote(&path.to_string_lossy())));
327+ self.call(json!({"op": "project", "slug": slug, "path": path}).to_string());
344328 }
345329
346330 /// The user's call on a widget build on trial (a `widgets` ticket in review): keep merges it
@@ -349,13 +333,13 @@ impl Live {
349333 if let Some(t) = self.data.tickets.iter_mut().find(|t| t.project == "widgets" && t.id == id && t.state == "review") {
350334 (t.state, t.since) = ((if keep { "done" } else { "draft" }).to_owned(), now() as u64);
351335 }
352- self.call(format!("{{\"op\":\"{}\",\"id\":{id}}}", if keep { "keep" } else { "discard" }));
336+ self.call(json!({"op": if keep { "keep" } else { "discard" }, "id": id}).to_string());
353337 }
354338
355339 /// How many of a project's tickets run at once. 0 pauses it. Shown at once.
356340 pub fn set_slots(&mut self, project: &str, slots: u32) {
357341 if let Some(p) = self.data.projects.iter_mut().find(|p| p.slug == project) { p.slots = slots; }
358- self.call(format!("{{\"op\":\"project\",\"slug\":{},\"slots\":{slots}}}", quote(project)));
342+ self.call(json!({"op": "project", "slug": project, "slots": slots}).to_string());
359343 }
360344 }
361345
@@ -494,10 +478,10 @@ impl Live {
494478 out.map_err(|msg| self.broken.get_mut().insert(id.to_owned(), msg)).ok()
495479 }
496480
497- /// Writes what the preview needs to show the app as it is now: `data.tsv` beside the
481+ /// Writes what the preview needs to show the app as it is now: `data.json` beside the
498482 /// instance folders and shared values, and `click`, the instance and element to outline.
499483 pub fn save_state(&self, instance: &str, element: &str) {
500- let _ = std::fs::write(self.base.join("data.tsv"), self.data.to_tsv());
484+ let _ = std::fs::write(self.base.join("data.json"), serde_json::to_string(&self.data).unwrap_or_default());
501485 let _ = std::fs::write(self.base.join("click"), format!("{instance}\t{element}\n"));
502486 }
503487
@@ -513,10 +497,6 @@ impl Live {
513497 ids.join("\n")
514498 }
515499
516- pub fn shared_line(&self) -> String {
517- self.shared.iter().map(|(k, v)| format!("{k}={v}")).collect::<Vec<_>>().join(", ")
518- }
519-
520500 /// Requests widgets made for conveyord since the last call.
521501 pub fn take_outbox(&mut self) -> Vec<String> {
522502 std::mem::take(&mut self.outbox)
@@ -540,57 +520,6 @@ impl Live {
540520 }
541521 }
542522
543-// ── Data as text: the app saves it with its state, and the preview loads it ─────────────────
544-
545-fn esc(s: &str) -> String {
546- s.replace('\\', "\\\\").replace('\t', "\\t").replace('\n', "\\n")
547-}
548-
549-fn unesc(s: &str) -> String {
550- let (mut out, mut it) = (String::new(), s.chars());
551- while let Some(c) = it.next() {
552- out.push(if c != '\\' { c } else { match it.next() { Some('t') => '\t', Some('n') => '\n', Some(o) => o, None => break } });
553- }
554- out
555-}
556-
557-impl Data {
558- /// One line per project (P), ticket (T), ticket conversation entry (H) and activity (A).
559- pub fn to_tsv(&self) -> String {
560- let line = |f: Vec<String>| f.iter().map(|x| esc(x)).collect::<Vec<_>>().join("\t") + "\n";
561- let act = |tag: &str, a: &Activity| line(vec![tag.into(), a.at.to_string(), a.project.clone(), a.ticket.to_string(), a.kind.clone(), a.text.clone()]);
562- let mut out = String::new();
563- for p in &self.projects { out += &line(vec!["P".into(), p.slug.clone(), p.path.clone(), p.slots.to_string()]); }
564- for t in &self.tickets {
565- let mut f = vec!["T".into(), t.project.clone(), t.id.to_string(), t.state.clone(), t.created.to_string(), t.since.to_string(), t.title.clone(), t.body.clone()];
566- f.extend(t.files.iter().cloned());
567- out += &line(f);
568- for a in &t.thread { out += &act("H", a); }
569- }
570- for a in &self.activity { out += &act("A", a); }
571- out
572- }
573-
574- pub fn from_tsv(text: &str) -> Data {
575- let mut d = Data::default();
576- for l in text.lines() {
577- let f: Vec<String> = l.split('\t').map(unesc).collect();
578- let g = |i: usize| f.get(i).cloned().unwrap_or_default();
579- let n = |i: usize| g(i).parse::<u64>().unwrap_or(0);
580- let act = || Activity { at: n(1), project: g(2), ticket: n(3) as u32, kind: g(4), text: g(5) };
581- match g(0).as_str() {
582- "P" => d.projects.push(Project { slug: g(1), path: g(2), slots: n(3) as u32 }),
583- "T" => d.tickets.push(Ticket { project: g(1), id: n(2) as u32, state: g(3), created: n(4), since: n(5), title: g(6), body: g(7),
584- files: f.iter().skip(8).cloned().collect(), thread: vec![] }),
585- "H" => if let Some(t) = d.tickets.last_mut() { t.thread.push(act()) },
586- "A" => d.activity.push(act()),
587- _ => {}
588- }
589- }
590- d
591- }
592-}
593-
594523 pub fn now() -> f64 {
595524 std::time::SystemTime::now().duration_since(std::time::UNIX_EPOCH).map_or(0.0, |d| d.as_secs_f64())
596525 }
templates/library/preview/Cargo.toml+2−0
@@ -5,4 +5,6 @@ edition = "2024"
55
66 [dependencies]
77 rune = { git = "https://github.com/anomalyco/rune", rev = "3ff3cc6152b9034a1d996e3a5575c51fab3b56b8", features = ["native-file-dialog"] }
8+serde = { version = "1", features = ["derive"] }
9+serde_json = "1"
810 rune-kit = { git = "https://github.com/anomalyco/rune", rev = "3ff3cc6152b9034a1d996e3a5575c51fab3b56b8", features = ["markdown"] }
templates/library/preview/src/main.rs+2−1
@@ -74,7 +74,8 @@ fn replay(state: &Path, base: &Path) -> (Data, Option<(String, String)>) {
7474 for f in ["w", "shared.tsv"].map(|f| state.join(f)).iter().filter(|f| f.exists()) {
7575 let _ = std::process::Command::new("cp").arg("-r").arg(f).arg(base).status();
7676 }
77- let data = Data { connected: true, ..Data::from_tsv(&std::fs::read_to_string(state.join("data.tsv")).unwrap_or_default()) };
77+ let saved = std::fs::read_to_string(state.join("data.json")).ok().and_then(|s| serde_json::from_str(&s).ok());
78+ let data = Data { connected: true, ..saved.unwrap_or_default() };
7879 let click = std::fs::read_to_string(state.join("click")).ok()
7980 .and_then(|c| c.trim_end_matches('\n').split_once('\t').map(|(i, e)| (i.to_owned(), e.to_owned())));
8081 (data, click)
tools/bake.py+6−89
@@ -1,15 +1,13 @@
11 #!/usr/bin/env python3
22 """Bakes conveyor's base VM image from the local CachyOS ISO, with QEMU run as the user.
3-conveyord runs every ticket in an overlay on this image. Run it again only to change the image.
3+conveyord runs every ticket in an overlay on this image. Run it again only to change the image:
4+delete images/base.qcow2 first.
45
5- tools/bake.py bake install the ISO into base.qcow2, provision it, pre-build the widget library
6- tools/bake.py up NAME (debugging) boot an overlay; ssh NAME, down NAME, ls, snap, restore
7- vm.py snap NAME TAG snapshot disk and RAM inside the overlay
8- vm.py restore NAME TAG go back to a snapshot and keep running
6+ tools/bake.py bake
97
10-State lives in ~/.local/share/conveyor-spike. Sockets live in /tmp/cv-*, because unix socket paths max out at 108 bytes.
8+State lives in ~/.local/share/conveyor. Sockets live in /tmp/cv-*, because unix socket paths max out at 108 bytes.
119 """
12-import base64, json, os, socket, subprocess, sys, tempfile, time
10+import base64, json, socket, subprocess, sys, time
1311 from pathlib import Path
1412
1513 DATA = Path.home() / ".local/share/conveyor"
@@ -198,12 +196,6 @@ def poweroff(name, secs=120):
198196 Path(sock(name, k)).unlink(missing_ok=True)
199197
200198
201-def pss_mb(pid):
202- for line in Path(f"/proc/{pid}/smaps_rollup").read_text().splitlines():
203- if line.startswith("Pss:"):
204- return int(line.split()[1]) // 1024
205-
206-
207199 # ---------- bake ----------
208200
209201 INSTALLER_SETTINGS = {
@@ -314,80 +306,5 @@ def bake():
314306 log(f"base ready: {BASE} ({BASE.stat().st_size / 2**30:.1f} GiB) in {time.monotonic() - t0:.0f} s")
315307
316308
317-# ---------- snapshots: internal, inside the overlay, with RAM ----------
318-
319-def _job(c, cmd, **kw):
320- node = [b for b in c.call("query-block") if b.get("inserted")][0]["inserted"]["node-name"]
321- t0 = time.monotonic()
322- c.call(cmd, **{"job-id": f"{cmd}-{time.time_ns()}", **kw, **({"vmstate": node, "devices": [node]} if cmd != "snapshot-delete" else {"devices": [node]})})
323- while True:
324- jobs = c.call("query-jobs")
325- if all(j["status"] in ("concluded", "null") for j in jobs):
326- errs = [j.get("error") for j in jobs if j.get("error")]
327- for j in jobs:
328- c.call("job-dismiss", id=j["id"])
329- if errs:
330- raise RuntimeError(errs)
331- return round((time.monotonic() - t0) * 1000)
332- time.sleep(0.05)
333-
334-
335-def snap(name, tag):
336- return _job(qmp(name), "snapshot-save", tag=tag)
337-
338-
339-def restore(name, tag):
340- c = qmp(name)
341- ms = _job(c, "snapshot-load", tag=tag)
342- c.call("cont")
343- return ms
344-
345-
346-# ---------- overlays ----------
347-
348-def up(name, mem_mb=8192):
349- VMS.mkdir(parents=True, exist_ok=True)
350- disk = VMS / f"{name}.qcow2"
351- t0 = time.monotonic()
352- subprocess.run(["qemu-img", "create", "-q", "-f", "qcow2", "-b", str(BASE), "-F", "qcow2", str(disk)], check=True)
353- t_overlay = time.monotonic() - t0
354- pid = boot(name, disk, mem_mb)
355- ok = wait_ssh(name, 300)
356- t_ssh = time.monotonic() - t0
357- res = {"name": name, "mem_mb": mem_mb, "overlay_ms": round(t_overlay * 1000), "ssh_s": round(t_ssh, 1) if ok else None,
358- "pss_mb_at_ssh": pss_mb(pid), "overlay_mb": round(disk.stat().st_size / 2**20, 1)}
359- print(json.dumps(res), flush=True)
360- return res
361-
362-
363-def down(name):
364- poweroff(name)
365- (VMS / f"{name}.qcow2").unlink(missing_ok=True)
366-
367-
368-def ls():
369- for p in sorted(Path("/tmp").glob("cv-*.pid")):
370- pid = int(p.read_text() or 0)
371- if pid and Path(f"/proc/{pid}").exists():
372- print(p.stem[3:], pid, f"{pss_mb(pid)} MB PSS")
373-
374-
375309 if __name__ == "__main__":
376- cmd, args = (sys.argv[1], sys.argv[2:]) if len(sys.argv) > 1 else ("help", [])
377- if cmd == "bake":
378- bake()
379- elif cmd == "up":
380- up(args[0], int(args[1]) if len(args) > 1 else 8192)
381- elif cmd == "down":
382- down(args[0])
383- elif cmd == "ssh":
384- os.execvp("ssh", ["ssh", "-i", str(KEY), "-p", str(ssh_port(args[0])), "-o", "StrictHostKeyChecking=no",
385- "-o", "UserKnownHostsFile=/dev/null", "-o", "LogLevel=ERROR", f"{USER}@127.0.0.1", *args[1:]])
386- elif cmd == "snap":
387- print(json.dumps({"snap_ms": snap(args[0], args[1])}))
388- elif cmd == "restore":
389- print(json.dumps({"restore_ms": restore(args[0], args[1])}))
390- elif cmd == "ls":
391- ls()
392- else:
393- print(__doc__)
310+ bake() if sys.argv[1:] == ["bake"] else print(__doc__)