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
Add the data folder and config.toml
emanuele-em6750044d2f9a
diff --git a/Cargo.lock b/Cargo.lockindex 331ac0b..6a9fb66 100644--- a/Cargo.lock+++ b/Cargo.lock@@ -2,6 +2,12 @@# It is not intended for manual editing.version = 4+[[package]]+name = "anyhow"+version = "1.0.104"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "330a5ed07fa54e4702c9d6c4174f74427fc0ef6e214bbd677ae50a5099946470"+[[package]]name = "bitflags"version = "2.13.2"@@ -24,6 +30,33 @@ version = "1.0.5"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"+[[package]]+name = "dirs"+version = "7.0.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "8d57d423b3c82e89b9a24ca3091fee61f456a26edbd28d26c65906f4bc1dcd8f"+dependencies = [+ "dirs-sys",+]++[[package]]+name = "dirs-sys"+version = "0.5.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "e01a3366d27ee9890022452ee61b2b63a67e6f13f58900b651ff5665f0bb1fab"+dependencies = [+ "libc",+ "option-ext",+ "redox_users",+ "windows-sys",+]++[[package]]+name = "equivalent"+version = "1.0.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "00d174d5400e5e8fd687ad1049e2f578285fa914201b1af7e8b112a4546bd826"+[[package]]name = "errno"version = "0.3.14"@@ -93,13 +126,26 @@ dependencies = ["hashbrown",]+[[package]]+name = "indexmap"+version = "2.14.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "cc4e190f5d26ca7051642629da2c52fc03bde85a03197c99408dcd291734c855"+dependencies = [+ "equivalent",+ "hashbrown",+]+[[package]]name = "kanzo"version = "0.1.0"dependencies = [+ "anyhow",+ "dirs","rusqlite","serde","tempfile",+ "toml",][[package]]@@ -108,6 +154,15 @@ version = "0.2.191"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "65cd87c9a6d60536580b316ad985726104730a5151c99845f2490428ef91240a"+[[package]]+name = "libredox"+version = "0.1.25"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "61ff90caf6077a803a240f62fdbe88645a890bbca49ef8174c3cb0404362171d"+dependencies = [+ "libc",+]+[[package]]name = "libsqlite3-sys"version = "0.39.1"@@ -131,6 +186,12 @@ version = "1.21.4"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"+[[package]]+name = "option-ext"+version = "0.2.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "04744f49eae99ab78e0d5c0b603ab218f515ea8cfe5a456d7629ad883a3b6e7d"+[[package]]name = "pkg-config"version = "0.3.34"@@ -161,6 +222,16 @@ version = "6.0.0"source = "registry+https://github.com/rust-lang/crates.io-index"checksum = "f8dcc9c7d52a811697d2151c701e0d08956f92b0e24136cf4cf27b57a6a0d9bf"+[[package]]+name = "redox_users"+version = "0.5.3"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "60dc65c0ff1a7ae1294b0c67b9f14baf70b644404010370171787bfac1038fc0"+dependencies = [+ "libredox",+ "thiserror",+]+[[package]]name = "rsqlite-vfs"version = "0.2.0"@@ -228,6 +299,15 @@ dependencies = ["syn",]+[[package]]+name = "serde_spanned"+version = "1.1.2"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "4e7523beb55eece201a2356bee0bbca0d1ab466c14c07703b2e0ee6d42cb0c2c"+dependencies = [+ "serde_core",+]+[[package]]name = "shlex"version = "2.0.1"@@ -294,6 +374,45 @@ dependencies = ["syn",]+[[package]]+name = "toml"+version = "1.1.8+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "20489e00e4d8741d6be680764cc12e270655e375a20d1011e844a9c3379e678d"+dependencies = [+ "indexmap",+ "serde_core",+ "serde_spanned",+ "toml_datetime",+ "toml_parser",+ "toml_writer",+ "winnow",+]++[[package]]+name = "toml_datetime"+version = "1.1.2+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "2b86d767906c6c42421dcba507eb9d203e779497710a47782a224bb871653053"+dependencies = [+ "serde_core",+]++[[package]]+name = "toml_parser"+version = "1.1.5+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "baa693a8032d7e1cada7d0041e96126df243179ff061456783ac7f12bda4744c"+dependencies = [+ "winnow",+]++[[package]]+name = "toml_writer"+version = "1.1.3+spec-1.1.0"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "06bdbd8cfc056b8d2e2e85f29b56a3bdbecb527cef81eb39e3e7b98af4652770"+[[package]]name = "unicode-ident"version = "1.0.27"@@ -320,3 +439,9 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"dependencies = ["windows-link",]++[[package]]+name = "winnow"+version = "1.0.4"+source = "registry+https://github.com/rust-lang/crates.io-index"+checksum = "23b97319f7b8343df12cc98938e5c3eb436064524c8d2b4e30a1d3a36eecdf81"diff --git a/Cargo.toml b/Cargo.tomlindex 7de1e31..7d801e8 100644--- a/Cargo.toml+++ b/Cargo.toml@@ -11,8 +11,11 @@ keywords = ["kanban", "mcp", "agents", "todo", "board"]categories = ["command-line-utilities"][dependencies]+anyhow = "1.0.104"+dirs = "7.0.0"rusqlite = { version = "0.41.0", features = ["bundled"] }serde = { version = "1.0.229", features = ["derive"] }+toml = "1.1.8"[dev-dependencies]tempfile = "3.27.0"diff --git a/src/home.rs b/src/home.rsnew file mode 100644index 0000000..0e7e07e--- /dev/null+++ b/src/home.rs@@ -0,0 +1,162 @@+//! The data folder: where it is, what it holds, and the settings in `config.toml`.++use std::fs::{self, File, OpenOptions};+use std::path::{Path, PathBuf};++use anyhow::{Context, Result, bail};+use serde::Deserialize;++use crate::store::Store;++pub const DEFAULT_PORT: u16 = 4242;++const CONFIG_TEMPLATE: &str = r#"# Kanzo settings.++# Port for the board at http://localhost:<port>.+port = 4242++# Board columns, left to right. New tasks go in the first one;+# tasks in the last one count as done.+statuses = ["todo", "doing", "review", "done"]+"#;++const GITIGNORE: &str = "\+# SQLite temporary files; kanzo sync folds them into kanzo.db first.+kanzo.db-wal+kanzo.db-shm+kanzo.db-journal+# Local to this machine.+kanzo.lock+*.bak+";++#[derive(Debug, Clone, Deserialize)]+#[serde(default, deny_unknown_fields)]+pub struct Config {+ pub port: u16,+ pub statuses: Vec<String>,+}++impl Default for Config {+ fn default() -> Self {+ Self { port: DEFAULT_PORT, statuses: ["todo", "doing", "review", "done"].map(String::from).to_vec() }+ }+}++impl Config {+ fn validate(&self) -> Result<()> {+ if self.statuses.len() < 2 {+ bail!("config.toml: `statuses` needs at least two columns");+ }+ for (i, s) in self.statuses.iter().enumerate() {+ if s.is_empty() || !s.chars().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || c == '-' || c == '_')+ {+ bail!("config.toml: status {s:?} must be lowercase letters, digits, - or _");+ }+ if self.statuses[..i].contains(s) {+ bail!("config.toml: status {s:?} is listed twice");+ }+ }+ Ok(())+ }+}++/// An opened data folder.+#[derive(Debug, Clone)]+pub struct Home {+ pub dir: PathBuf,+ pub config: Config,+}++impl Home {+ /// `--home`, then `KANZO_HOME`, then `~/kanzo`.+ pub fn resolve(flag: Option<PathBuf>) -> Result<PathBuf> {+ if let Some(dir) = flag {+ return Ok(dir);+ }+ if let Some(dir) = std::env::var_os("KANZO_HOME").filter(|v| !v.is_empty()) {+ return Ok(PathBuf::from(dir));+ }+ let home = dirs::home_dir().context("cannot find your home folder; set KANZO_HOME")?;+ Ok(home.join("kanzo"))+ }++ /// Opens the data folder, creating it and its files on first use.+ pub fn open(dir: PathBuf) -> Result<Self> {+ fs::create_dir_all(&dir).with_context(|| format!("cannot create {}", dir.display()))?;+ let dir = dir.canonicalize().unwrap_or(dir);+ write_if_missing(&dir.join("config.toml"), CONFIG_TEMPLATE)?;+ write_if_missing(&dir.join(".gitignore"), GITIGNORE)?;++ let path = dir.join("config.toml");+ let text = fs::read_to_string(&path).with_context(|| format!("cannot read {}", path.display()))?;+ let config: Config = toml::from_str(&text).with_context(|| format!("{} is not valid", path.display()))?;+ config.validate()?;++ let home = Self { dir, config };+ home.store()?.migrate()?;+ Ok(home)+ }++ pub fn db_path(&self) -> PathBuf {+ self.dir.join("kanzo.db")+ }++ /// Opens a fresh connection. Callers keep it for one operation only, so a+ /// database replaced by `kanzo sync` is picked up on the next one. It holds+ /// a shared lock on `kanzo.lock`, so sync can wait for it to finish.+ pub fn store(&self) -> Result<Store> {+ let lock = self.lock_file()?;+ // Some filesystems (exFAT, network shares) have no locks; go on without.+ let lock = lock.lock_shared().ok().map(|_| lock);+ Ok(Store::open(&self.db_path(), self.config.statuses.clone(), lock)?)+ }++ /// Blocks until no connection is open, and keeps new ones out until the file is dropped.+ pub fn lock_exclusive(&self) -> Result<Option<File>> {+ let lock = self.lock_file()?;+ Ok(lock.lock().ok().map(|_| lock))+ }++ fn lock_file(&self) -> Result<File> {+ let path = self.dir.join("kanzo.lock");+ OpenOptions::new()+ .create(true)+ .truncate(false)+ .write(true)+ .open(&path)+ .with_context(|| format!("cannot open {}", path.display()))+ }+}++fn write_if_missing(path: &Path, contents: &str) -> Result<()> {+ if !path.exists() {+ fs::write(path, contents).with_context(|| format!("cannot write {}", path.display()))?;+ }+ Ok(())+}++#[cfg(test)]+mod tests {+ use super::*;++ #[test]+ fn first_open_creates_files() {+ let tmp = tempfile::tempdir().unwrap();+ let dir = tmp.path().join("data");+ let home = Home::open(dir.clone()).unwrap();+ assert!(dir.join("config.toml").exists());+ assert!(dir.join(".gitignore").exists());+ assert!(dir.join("kanzo.db").exists());+ assert_eq!(home.config.port, DEFAULT_PORT);+ assert_eq!(home.config.statuses, ["todo", "doing", "review", "done"]);+ }++ #[test]+ fn rejects_bad_statuses() {+ let tmp = tempfile::tempdir().unwrap();+ fs::write(tmp.path().join("config.toml"), "statuses = [\"todo\", \"todo\"]\n").unwrap();+ let err = Home::open(tmp.path().to_path_buf()).unwrap_err();+ assert!(err.to_string().contains("listed twice"), "{err}");+ }+}diff --git a/src/main.rs b/src/main.rsindex ba44efd..bba7bf4 100644--- a/src/main.rs+++ b/src/main.rs@@ -1,3 +1,4 @@+mod home;mod store;fn main() {}