xonecas.io
8447
Co

conveyor / commit a1a5277

Widgets get serde in the app, a secrets store, and failed builds resume

#23 rendered in its VM and failed on trial: the ponytail pass gave the
preview serde_json, but not conveyor-widgets. Both now offer rune,
rune_kit, serde and serde_json, and the trial test's widget uses
serde_json, so a mismatch fails the test, not a user's build.

A widget asking for an API key had nowhere safe to keep it: cx.dir is in
the app state that every build ticket copies into its VM.
set_secret/cx.secret keep secrets in ~/.local/share/conveyor/secrets
(0700, files 0600), beside the app state, never in it.

A failed or parked ticket made ready again now continues its own branch,
and its agent is told why it stopped; #12 and #23 both lost their work.
Discard deletes the branch, so Ready after a discard starts fresh.

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-09 a1a527792817333d879acf1e62fbb6affd4be00a parent 2730027

7 files changed

Cargo.lock+2−0
@@ -612,6 +612,8 @@ dependencies = [
612612 "conveyor-app",
613613 "rune",
614614 "rune-kit",
615+ "serde",
616+ "serde_json",
615617 ]
616618
617619 [[package]]
crates/conveyor-widgets/Cargo.toml+3−0
@@ -12,3 +12,6 @@ crate-type = ["dylib"]
1212 conveyor-app = { path = "../conveyor-app" }
1313 rune.workspace = true
1414 rune-kit.workspace = true
15+# What the template's preview gives widgets too: a widget that builds there must build here.
16+serde.workspace = true
17+serde_json.workspace = true
crates/conveyor/src/agent.rs+14−2
@@ -37,7 +37,10 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
3737 let (url, git_ssh) = vm.git_remote("/home/sacenox/work");
3838 // A widget build starts from what the user sees: the library with every build on trial.
3939 git(&p.path, &git_ssh, &["push", "-q", &url, if p.library { library::BASE } else { "main:main" }])?;
40- vm.sh(&format!("cd ~/work && git switch -qc {branch}"), b"")?;
40+ // A ticket that ran before (it failed, or was parked) picks up its own branch.
41+ let resumed = git(&p.path, "", &["rev-parse", "-q", "--verify", &branch]).is_ok();
42+ if resumed { git(&p.path, &git_ssh, &["push", "-q", &url, &format!("{branch}:{branch}")])?; }
43+ vm.sh(&format!("cd ~/work && git switch -q{} {branch}", if resumed { "" } else { "c" }), b"")?;
4144 let files = give_files(&vm, p, id)?;
4245
4346 let local = crate::paths::vm_sock(&name, "verbs");
@@ -53,7 +56,8 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
5356 --disallowedTools=AskUserQuestion --append-system-prompt \"$(cat ~/.conveyor/rules.md)\""))
5457 .stdin(Stdio::piped()).stdout(stream).stderr(Stdio::piped())
5558 .spawn().map_err(|e| e.to_string())?;
56- agent.stdin.take().unwrap().write_all(format!("# #{id} {}\n\n{}{files}", t.title, t.body).as_bytes()).map_err(|e| e.to_string())?;
59+ let before = if resumed { stopped(&p.slug, id) } else { String::new() };
60+ agent.stdin.take().unwrap().write_all(format!("# #{id} {}\n\n{}{files}{before}", t.title, t.body).as_bytes()).map_err(|e| e.to_string())?;
5761 let out = agent.wait_with_output().map_err(|e| e.to_string())?;
5862 let outcome = verbs.finish();
5963 if let Some(reply) = reply(&store::dir(&p.slug, id).join("stream.jsonl")) {
@@ -88,6 +92,14 @@ pub(crate) fn merges_onto(p: &Project, url: &str, git_ssh: &str, branch: &str) -
8892 }
8993 }
9094
95+/// For a ticket that ran before: where its work is, and why it stopped.
96+fn stopped(project: &str, id: u32) -> String {
97+ let why = store::events(project, id).into_iter().rev()
98+ .find_map(|e| e["msg"].as_str().filter(|_| e["kind"] == "error").or(e["args"]["reason"].as_str().filter(|_| e["verb"] == "block")).map(String::from))
99+ .unwrap_or_else(|| "it stopped before finishing".into());
100+ format!("\n\nThis ticket ran before. Its work is on your branch (`git log main..`): continue from it. It stopped because:\n\n{why}")
101+}
102+
91103 /// Copies the ticket's attached files to ~/ticket/files in the guest. What the prompt says of them.
92104 fn give_files(vm: &Vm, p: &Project, id: u32) -> Result<String, String> {
93105 let names: Vec<String> = store::files(&p.slug, id).iter().filter_map(|f| Some(f.file_name()?.to_str()?.to_owned())).collect();
crates/conveyor/src/library.rs+3−1
@@ -155,11 +155,13 @@ pub fn keep(id: u32) -> Result<(), String> {
155155 trial(None)
156156 }
157157
158-/// Discards a build on trial: back to draft, out of the app. Ready builds it again.
158+/// Discards a build on trial: back to draft, out of the app, its branch gone. Ready builds it again.
159159 pub fn discard(id: u32) -> Result<(), String> {
160160 store::ticket(SLUG, id).filter(|t| t.state == "review").ok_or("that build isn't on trial")?;
161161 store::set_state(SLUG, id, "draft");
162162 store::event(SLUG, id, json!({"kind": "conveyor", "msg": "discarded: back to draft"}));
163+ // Ready builds it again from scratch, not from the discarded attempt.
164+ let _ = git(&paths::library(), "", &["branch", "-D", &format!("t-{id}")]);
163165 trial(None)
164166 }
165167
crates/conveyor/src/library_tests.rs+2−2
@@ -6,7 +6,7 @@ use std::path::PathBuf;
66
77 const WIDGET: &str = "use super::api::*;\nuse rune::{El, col};\n\
88 pub const WIDGET: Widget = Widget { title: \"T\", size: (10.0, 10.0), new: |_| Box::new(T) };\n\
9- pub struct T;\nimpl View for T { fn view(&self, _: &Cx) -> El { col() } }\n";
9+ pub struct T;\nimpl View for T { fn view(&self, _: &Cx) -> El { let _ = serde_json::json!({}); col() } }\n";
1010
1111 fn run(dir: &Path, args: &[&str]) -> String {
1212 git(dir, "", &[&COMMIT[..], args].concat()).unwrap()
@@ -93,5 +93,5 @@ fn trial_edges() {
9393 try_out(&p, e, &branch_e).unwrap();
9494 assert!(has(&branch_e, "trial"));
9595 discard(e).unwrap();
96- assert!(state(e) == "draft" && !has(&branch_e, "trial") && !has(&branch_e, "main"));
96+ assert!(state(e) == "draft" && !has(&branch_e, "trial") && git(&paths::library(), "", &["rev-parse", "-q", "--verify", &branch_e]).is_err());
9797 }
templates/library/CLAUDE.md+2−0
@@ -40,10 +40,12 @@ A widget is a struct with its own state that renders itself (`api::View`). Read
4040 - **Key what a user can point at.** Give cards, buttons, columns and panes stable, meaningful keys (`card-{id}`, `col-done`, `add-project`). The Ctrl+click outline and the ticket's element path come from keys; unkeyed parts are invisible to the builder.
4141 - **Animate.** Call `cx.animate()` in `view` while something moves, and draw from `cx.now`. Without it the app renders once a second.
4242 - **Files.** `cx.dir` is the instance's own folder and survives reloads and restarts.
43+- **Secrets.** An API key, token or password the user types goes to `set_secret(h, "openrouter", &key)` in a handler (or `cx.act(|l| l.set_secret(..))`), and comes back with `cx.secret("openrouter")`. Never keep one in `cx.dir`, a shared value or any file you write: the user's app state is copied into every build ticket, and secrets aren't. Pass a secret to `curl` on stdin, not in its arguments.
4344 - **Say what it is.** The first paragraph of a widget file's `//!` comment is its description: the library shows it to the user picking widgets (`cx.about(kind)`). One or two plain sentences on what it shows and does.
4445 - **A panic stops only that instance.** It draws a red card with the message until the next build, and the user can Ctrl+click it to have it fixed. If `root` or `status` stops, the app opens safe mode, where no widget runs.
4546 - **Background work.** `std::thread`, and the system's programs with `std::process::Command` (`curl` for the network: std has no HTTPS).
4647 - **Images.** `cx.images()` is the app's image cache: `.load(bytes)`, `.file(path, ..)` and `.svg(..)` decode off the UI thread, and the app redraws when one is ready. Keep the handle in your state to load from handlers. Don't make your own `ImageCache`. `rune::Pixels` streams raw frames.
48+- **Crates.** `rune`, `rune_kit`, `serde` (with derive) and `serde_json`, and std. Nothing else links: a widget that needs another crate is a block.
4749 - **Components.** `rune_kit` is there too: syntax highlighting (`rune_kit::syntax`), Markdown, menus, popovers, tables, trees, dialogs, toasts and more. Use them before writing your own. Its source is next to rune's (`~/.cargo/git/checkouts/rune-*/*/crates/rune-kit/`).
4850
4951 ## When to block instead
templates/library/api.rs+31−2
@@ -140,6 +140,12 @@ impl Cx<'_> {
140140 self.live.shared.get(key).map(String::as_str)
141141 }
142142
143+ /// A secret the user gave a widget, such as an API key, set with `set_secret`. Read it where
144+ /// you use it (a handler, or before starting a thread), not in `view`: it's a file read.
145+ pub fn secret(&self, name: &str) -> Option<String> {
146+ self.live.secret(name)
147+ }
148+
143149 /// Ask for frames at the display's rate while this keeps being called: for animation.
144150 pub fn animate(&self) {
145151 self.live.animate.set(true);
@@ -220,6 +226,11 @@ pub fn share(h: &mut HostState, key: &str, value: &str) {
220226 Host::live(h).share(key, value)
221227 }
222228
229+/// Keeps a secret, such as an API key, where build tickets never see it. Empty forgets it.
230+pub fn set_secret(h: &mut HostState, name: &str, value: &str) {
231+ Host::live(h).set_secret(name, value)
232+}
233+
223234 /// Sends one request to conveyord. The ops are in conveyor's server.rs.
224235 pub fn call(h: &mut HostState, request: String) {
225236 Host::live(h).call(request)
@@ -268,6 +279,8 @@ pub struct Live {
268279 /// Instances whose code panicked, with the message. They draw `stopped` until the next build.
269280 broken: RefCell<BTreeMap<String, String>>,
270281 base: PathBuf,
282+ /// Beside `base`, never in it: the app's state is copied into every build ticket.
283+ secrets: PathBuf,
271284 instances: HashMap<String, (String, Box<dyn View>)>,
272285 shared: BTreeMap<String, String>,
273286 wanted: RefCell<Vec<(String, String)>>,
@@ -291,6 +304,21 @@ impl Live {
291304 self.dirty = true;
292305 }
293306
307+ /// Keeps a secret where build tickets never see it, readable by the user alone. Empty forgets it.
308+ pub fn set_secret(&mut self, name: &str, value: &str) {
309+ use std::{io::Write, os::unix::fs::{DirBuilderExt, OpenOptionsExt}};
310+ let path = self.secrets.join(name.replace('/', "_"));
311+ if value.is_empty() { let _ = std::fs::remove_file(path); return; }
312+ let _ = std::fs::DirBuilder::new().recursive(true).mode(0o700).create(&self.secrets);
313+ let file = std::fs::OpenOptions::new().write(true).create(true).truncate(true).mode(0o600).open(path);
314+ let _ = file.and_then(|mut f| f.write_all(value.as_bytes()));
315+ }
316+
317+ /// A secret, as `cx.secret` reads it.
318+ pub fn secret(&self, name: &str) -> Option<String> {
319+ std::fs::read_to_string(self.secrets.join(name.replace('/', "_"))).ok().filter(|s| !s.is_empty())
320+ }
321+
294322 /// Sends one request to conveyord, as `conveyor call` does. The ops are in conveyor's
295323 /// server.rs. Results show up in `cx.data` within a second.
296324 pub fn call(&mut self, request: String) {
@@ -344,7 +372,8 @@ impl Live {
344372 }
345373
346374 impl Live {
347- /// Instances of `kinds` keep their folders under `base`, and shared values in `base/shared.tsv`.
375+ /// Instances of `kinds` keep their folders under `base`, shared values in `base/shared.tsv`,
376+ /// and secrets in `secrets` beside it.
348377 pub fn new(base: PathBuf, kinds: Kinds, about: Abouts) -> Self {
349378 let shared = std::fs::read_to_string(base.join("shared.tsv")).unwrap_or_default().lines()
350379 .filter_map(|l| l.split_once('\t').map(|(k, v)| (k.to_owned(), v.replace("\\n", "\n"))))
@@ -352,7 +381,7 @@ impl Live {
352381 // Instances that were keeping work going come back now, shown or not.
353382 let wanted: Vec<(String, String)> = std::fs::read_to_string(base.join("running.tsv")).unwrap_or_default().lines()
354383 .filter_map(|l| l.split_once('\t').map(|(id, kind)| (id.to_owned(), kind.to_owned()))).collect();
355- Live { data: Data::default(), kinds, about, broken: RefCell::new(BTreeMap::new()), waker: std::sync::Arc::new(|| {}), images: OnceCell::new(), base, instances: HashMap::new(), shared, wanted: RefCell::new(wanted),
384+ Live { data: Data::default(), kinds, about, broken: RefCell::new(BTreeMap::new()), waker: std::sync::Arc::new(|| {}), images: OnceCell::new(), secrets: base.with_file_name("secrets"), base, instances: HashMap::new(), shared, wanted: RefCell::new(wanted),
356385 animate: Cell::new(false), outbox: vec![], spare: TextEdit::new(""), dirty: false,
357386 later: RefCell::new(vec![]), running: RefCell::new(BTreeSet::new()), kept: BTreeSet::new() }
358387 }