xonecas.io
8447
Co

conveyor / commit 9f8c1e2

The keychain reaches agents: secrets go into the VM as env vars, cx.secrets lists them

Each ticket's VM gets ~/.conveyor/env (0600) with one NAME='value' line per secret,
exported in the agent's shell; the prompt names the variables. rules.md says how to
pass a key. Widgets list the keychain's names with cx.secrets().

Co-Authored-By: Claude Opus 5.5

sacenox2026-11-10 9f8c1e267b0b9f7d18ce1906ee21832d20a217e0 parent a1a5277

5 files changed

crates/conveyor/src/agent.rs+20−2
@@ -26,6 +26,7 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
2626 note("booting VM");
2727 let vm = Vm::up(&name, 8192)?;
2828 give_agent_config(&vm)?;
29+ let keys = give_secrets(&vm)?;
2930 vm.sh("mkdir -p ~/.local/bin ~/.conveyor && cat > ~/.local/bin/conveyor && chmod +x ~/.local/bin/conveyor",
3031 // /proc/self/exe still reads after cargo replaces the binary; current_exe() would not.
3132 &std::fs::read("/proc/self/exe").map_err(|e| e.to_string())?)?;
@@ -51,13 +52,13 @@ fn run(p: &Project, id: u32) -> Result<String, String> {
5152 let stream = File::create(store::dir(&p.slug, id).join("stream.jsonl")).map_err(|e| e.to_string())?;
5253 let mut agent = vm.ssh()
5354 .args(["-o", "StreamLocalBindUnlink=yes", "-R", &format!("{remote}:{}", local.display())])
54- .arg(format!("cd ~/work && CONVEYOR_SOCK={remote} CARGO_TARGET_DIR=$HOME/.cache/conveyor-target PATH=$HOME/.local/bin:$PATH \
55+ .arg(format!("cd ~/work && set -a && . ~/.conveyor/env && set +a && CONVEYOR_SOCK={remote} CARGO_TARGET_DIR=$HOME/.cache/conveyor-target PATH=$HOME/.local/bin:$PATH \
5556 claude -p --output-format stream-json --verbose --dangerously-skip-permissions \
5657 --disallowedTools=AskUserQuestion --append-system-prompt \"$(cat ~/.conveyor/rules.md)\""))
5758 .stdin(Stdio::piped()).stdout(stream).stderr(Stdio::piped())
5859 .spawn().map_err(|e| e.to_string())?;
5960 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())?;
61+ agent.stdin.take().unwrap().write_all(format!("# #{id} {}\n\n{}{files}{keys}{before}", t.title, t.body).as_bytes()).map_err(|e| e.to_string())?;
6162 let out = agent.wait_with_output().map_err(|e| e.to_string())?;
6263 let outcome = verbs.finish();
6364 if let Some(reply) = reply(&store::dir(&p.slug, id).join("stream.jsonl")) {
@@ -116,6 +117,23 @@ fn reply(stream: &Path) -> Option<String> {
116117 .find(|v| v["type"] == "result")?["result"].as_str().map(String::from)
117118 }
118119
120+/// Writes the user's keychain to ~/.conveyor/env (0600) as `NAME='value'` lines; the agent's
121+/// shell exports them. A secret `openrouter` is `$OPENROUTER`. What the prompt says of them.
122+fn give_secrets(vm: &Vm) -> Result<String, String> {
123+ let mut env = String::new();
124+ let mut names = Vec::new();
125+ for e in std::fs::read_dir(crate::paths::secrets()).into_iter().flatten().flatten() {
126+ let Ok(value) = std::fs::read_to_string(e.path()) else { continue };
127+ let name: String = e.file_name().to_string_lossy().chars()
128+ .map(|c| if c.is_ascii_alphanumeric() { c.to_ascii_uppercase() } else { '_' }).collect();
129+ if value.is_empty() || name.starts_with(|c: char| c.is_ascii_digit()) { continue; }
130+ env += &format!("{name}='{}'\n", value.trim().replace('\'', "'\\''"));
131+ names.push(format!("`${name}`"));
132+ }
133+ vm.sh("mkdir -p ~/.conveyor && umask 077 && cat > ~/.conveyor/env", env.as_bytes())?;
134+ Ok(if names.is_empty() { String::new() } else { format!("\n\nThe user's keys, in your environment: {}.", names.join(", ")) })
135+}
136+
119137 fn give_agent_config(vm: &Vm) -> Result<(), String> {
120138 let home = std::env::var("HOME").map_err(|e| e.to_string())?;
121139 let files: Vec<&str> = AGENT_FILES.into_iter().filter(|f| Path::new(&home).join(f).exists()).collect();
crates/conveyor/src/paths.rs+5−0
@@ -23,6 +23,11 @@ pub fn trial() -> PathBuf {
2323 data().join("trial")
2424 }
2525
26+/// The user's keys, one 0600 file per name: the app's keychain. Agents get them as env vars.
27+pub fn secrets() -> PathBuf {
28+ data().join("secrets")
29+}
30+
2631 pub fn base_image() -> PathBuf {
2732 data().join("images/base.qcow2")
2833 }
crates/conveyor/src/rules.md+2−0
@@ -12,4 +12,6 @@ You talk to conveyor only through the `conveyor` command:
1212
1313 Never ask the user a question. Every question becomes a `decide`, a `deviate` or a `block`.
1414
15+The user's API keys, if the prompt lists any, are in your environment. Pass one to a command on stdin or through the environment, never in its arguments, and never write it into a file, a commit, a note or your answers.
16+
1517 Commit your work on the current branch, in logical commits. The repo's CLAUDE.md or AGENTS.md, if there is one, has the project's own rules.
templates/library/CLAUDE.md+1−1
@@ -40,7 +40,7 @@ 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.
43+- **Secrets.** The user keeps API keys, tokens and passwords in one keychain, by name. `cx.secrets()` lists the names, `cx.secret("openrouter")` reads one, and `set_secret(h, "openrouter", &key)` in a handler (or `cx.act(|l| l.set_secret(..))`) sets one; empty forgets it. A widget that needs a key lets the user pick one of those names, not type the key again. Never keep a key in `cx.dir`, a shared value or any file you write: the app state is copied into every build ticket. Pass a key to `curl` …
4444 - **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.
4545 - **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.
4646 - **Background work.** `std::thread`, and the system's programs with `std::process::Command` (`curl` for the network: std has no HTTPS).
templates/library/api.rs+16−3
@@ -140,12 +140,17 @@ 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
143+ /// A secret from the keychain, such as an API key, set with `set_secret`. Read it where
144144 /// you use it (a handler, or before starting a thread), not in `view`: it's a file read.
145145 pub fn secret(&self, name: &str) -> Option<String> {
146146 self.live.secret(name)
147147 }
148148
149+ /// The names of every secret the user keeps, sorted: the keychain. A folder read, like `secret`.
150+ pub fn secrets(&self) -> Vec<String> {
151+ self.live.secrets()
152+ }
153+
149154 /// Ask for frames at the display's rate while this keeps being called: for animation.
150155 pub fn animate(&self) {
151156 self.live.animate.set(true);
@@ -226,7 +231,7 @@ pub fn share(h: &mut HostState, key: &str, value: &str) {
226231 Host::live(h).share(key, value)
227232 }
228233
229-/// Keeps a secret, such as an API key, where build tickets never see it. Empty forgets it.
234+/// Keeps a secret, such as an API key, in the user's keychain, outside the app state. Empty forgets it.
230235 pub fn set_secret(h: &mut HostState, name: &str, value: &str) {
231236 Host::live(h).set_secret(name, value)
232237 }
@@ -304,7 +309,7 @@ impl Live {
304309 self.dirty = true;
305310 }
306311
307- /// Keeps a secret where build tickets never see it, readable by the user alone. Empty forgets it.
312+ /// Keeps a secret in the keychain, readable by the user alone. Empty forgets it.
308313 pub fn set_secret(&mut self, name: &str, value: &str) {
309314 use std::{io::Write, os::unix::fs::{DirBuilderExt, OpenOptionsExt}};
310315 let path = self.secrets.join(name.replace('/', "_"));
@@ -319,6 +324,14 @@ impl Live {
319324 std::fs::read_to_string(self.secrets.join(name.replace('/', "_"))).ok().filter(|s| !s.is_empty())
320325 }
321326
327+ /// The names of every secret, as `cx.secrets` lists them.
328+ pub fn secrets(&self) -> Vec<String> {
329+ let mut names: Vec<String> = std::fs::read_dir(&self.secrets).into_iter().flatten().flatten()
330+ .filter_map(|e| e.file_name().into_string().ok()).collect();
331+ names.sort();
332+ names
333+ }
334+
322335 /// Sends one request to conveyord, as `conveyor call` does. The ops are in conveyor's
323336 /// server.rs. Results show up in `cx.data` within a second.
324337 pub fn call(&mut self, request: String) {