Self-hosted, sharable kanban for humans and agents. One 4.7 MB binary, 5 MB of RAM, 10 to 60 tokens per agent reply, starts in 3 ms, zero setup.
Rust ai-agentsclaude-codeclicodexcoding-agentskanbanlocal-firstmcpmcp-servermodel-context-protocolproductivityproject-managementraspberry-pirustself-hostedsqlitetask-manager
Paste images into tasks as file paths
emanuele-em84fe2065f644
diff --git a/README.md b/README.mdindex f04fcac..e7a136a 100644--- a/README.md+++ b/README.md@@ -34,6 +34,8 @@ kanzo service install # keep it running and start it at login`n` adds a task, `/` searches, `Tab` moves to the description, `⌘↵` saves and closes, `Esc` cancels.+Paste an image into a task and Kanzo saves it in `~/kanzo/images` and types its path, like a terminal does, so your agents can open it.+## Connect your agents```shdiff --git a/src/app.js b/src/app.jsindex 76eedea..042a052 100644--- a/src/app.js+++ b/src/app.js@@ -763,6 +763,34 @@ $("#p-desc").addEventListener("blur", (e) => {$("#p-status").addEventListener("change", (e) => patchTask({ status: e.target.value }));+// Pasting an image saves it in the data folder and types its path, the way a terminal+// does, so agents can open it. Text pastes are left alone.+async function pasteImages(e) {+ const data = e.clipboardData;+ const fromItems = data && data.items ? [...data.items].filter((i) => i.kind === "file").map((i) => i.getAsFile()) : [];+ const images = (fromItems.length ? fromItems : [...((data && data.files) || [])]).filter((f) => f && f.type.startsWith("image/"));+ if (!images.length) return;+ e.preventDefault();+ const field = e.target;+ try {+ const paths = [];+ for (const image of images) {+ const res = await fetch("/api/images", { method: "POST", headers: { "Content-Type": image.type }, body: image });+ const reply = await res.json().catch(() => ({}));+ if (!res.ok) throw new Error(reply.error || res.statusText);+ paths.push(reply.path);+ }+ field.focus();+ // Keep the path apart from the words around it.+ const { value, selectionStart: start, selectionEnd: end } = field;+ const before = start > 0 && !/\s/.test(value[start - 1]) ? " " : "";+ const after = end < value.length && !/\s/.test(value[end]) ? " " : "";+ field.setRangeText(before + paths.join(" ") + after, start, end, "end");+ field.dispatchEvent(new Event("input"));+ } catch (err) { toast(err.message); }+}+for (const field of [$("#p-title"), $("#p-desc"), $("#p-comment")]) field.addEventListener("paste", pasteImages);+// Tags are typed comma-separated and tidied the way the server stores them.const cleanTags = (text) => [...new Set(text.split(",").map((t) => t.trim().replace(/\s+/g, " ").toLowerCase()).filter(Boolean))];$("#p-tags").addEventListener("keydown", (e) => {diff --git a/src/web.rs b/src/web.rsindex 6b57a37..9b2da9a 100644--- a/src/web.rs+++ b/src/web.rs@@ -4,8 +4,9 @@ use std::net::{IpAddr, Ipv6Addr, SocketAddr};use std::sync::Arc;use anyhow::{Context, Result, bail};-use axum::extract::{Path, Query, Request, State};-use axum::http::{HeaderValue, StatusCode, header};+use axum::body::Bytes;+use axum::extract::{DefaultBodyLimit, Path, Query, Request, State};+use axum::http::{HeaderMap, HeaderValue, StatusCode, header};use axum::middleware::{self, Next};use axum::response::{Html, IntoResponse, Response};use axum::routing::{delete, get, patch, post};@@ -19,6 +20,8 @@ use crate::home::Home;use crate::store::{self, Error, Store, TaskPatch};const INDEX: &str = include_str!("index.html");+/// The largest image the board takes from a paste.+const IMAGE_LIMIT: usize = 25 * 1024 * 1024;const APP_JS: &str = include_str!("app.js");const LOGO: &[u8] = include_bytes!("logo.png");@@ -129,6 +132,7 @@ fn router(home: Home, guard: Guard, shutdown: CancellationToken) -> Router {.route("/api/tasks/{id}/move", post(move_task)).route("/api/tasks/{id}/comments", post(add_comment)).route("/api/comments/{id}", delete(delete_comment))+ .route("/api/images", post(save_image).layer(DefaultBodyLimit::max(IMAGE_LIMIT))).layer(middleware::from_fn_with_state(Arc::new(guard), protect)).with_state(Arc::new(home))}@@ -397,6 +401,49 @@ async fn delete_comment(State(home): Shared, Path(id): Path<i64>) -> Response {with_store(home, move |_, s| s.delete_comment(id)).await}+/// Saves a pasted image in the data folder and answers with its path, which the board+/// puts in the text the way a terminal does, so agents can open the image. Files are+/// named by their content: the same image pasted twice is stored once.+async fn save_image(State(home): Shared, headers: HeaderMap, body: Bytes) -> Response {+ let ext = match headers.get(header::CONTENT_TYPE).and_then(|v| v.to_str().ok()) {+ Some("image/png") => "png",+ Some("image/jpeg") => "jpg",+ Some("image/gif") => "gif",+ Some("image/webp") => "webp",+ _ => {+ return (StatusCode::BAD_REQUEST, Json(json!({ "error": "paste a PNG, JPEG, GIF or WebP image" })))+ .into_response();+ }+ };+ if body.is_empty() {+ return (StatusCode::BAD_REQUEST, Json(json!({ "error": "the image is empty" }))).into_response();+ }+ let saved = tokio::task::spawn_blocking(move || -> std::io::Result<std::path::PathBuf> {+ use std::hash::{Hash, Hasher};+ let dir = home.dir.join("images");+ std::fs::create_dir_all(&dir)?;+ let mut hasher = std::collections::hash_map::DefaultHasher::new();+ body.hash(&mut hasher);+ let path = dir.join(format!("{:016x}.{ext}", hasher.finish()));+ if !path.exists() {+ // Write to a temporary name first, so a half-written image never has the real one.+ let partial = path.with_extension("part");+ std::fs::write(&partial, &body)?;+ std::fs::rename(&partial, &path)?;+ }+ Ok(path)+ })+ .await;+ match saved {+ Ok(Ok(path)) => Json(json!({ "path": path.display().to_string() })).into_response(),+ Ok(Err(e)) => {+ (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({ "error": format!("cannot save the image: {e}") })))+ .into_response()+ }+ Err(e) => (StatusCode::INTERNAL_SERVER_ERROR, Json(json!({ "error": e.to_string() }))).into_response(),+ }+}+/// True when the program on `port` answers like a Kanzo board.async fn is_kanzo(port: u16) -> bool {let probe = async {