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
Open boards from newer versions when possible, and add kanzo update
emanuele-em5ee16f1a0e8e
diff --git a/README.md b/README.mdindex 594c879..faf6094 100644--- a/README.md+++ b/README.md@@ -34,6 +34,7 @@ For macOS and Linux, including every Raspberry Pi. Or build it: `cargo install -| `kanzo mcp` | The MCP server for agents: they start it, not you || `kanzo sync` | Commits the board and pulls or pushes it; `--repo <url>` sets the repo, `--keep-local` or `--keep-remote` when both sides changed || `kanzo export` | Prints the board as Markdown; `-f json` for JSON, `-p <project>` for one project, `-o <file>` to save it |+| `kanzo update` | Installs the latest release and restarts the board's service; the board offers new versions too || `kanzo init` | Creates the data folder; the first run does this too || `kanzo --version` | Prints the version |diff --git a/src/main.rs b/src/main.rsindex e74432b..aaa2e51 100644--- a/src/main.rs+++ b/src/main.rs@@ -69,6 +69,8 @@ enum Command {#[arg(long, short, value_name = "FILE")]output: Option<PathBuf>,},+ /// Install the latest release over this Kanzo, and restart the board's service+ Update,/// Start the board automatically at login (macOS and Linux)Service {#[command(subcommand)]@@ -105,6 +107,10 @@ fn main() -> ExitCode {}async fn run(cli: Cli) -> anyhow::Result<()> {+ // Before opening the data folder: it may be the reason to update.+ if let Some(Command::Update) = cli.command {+ return update_kanzo();+ }let dir = match &cli.command {Some(Command::Init { folder: Some(folder) }) => folder.clone(),_ => Home::resolve(cli.home)?,@@ -134,5 +140,26 @@ async fn run(cli: Cli) -> anyhow::Result<()> {}Some(Command::Service { action: ServiceAction::Install }) => service::install(&home),Some(Command::Service { action: ServiceAction::Uninstall }) => service::uninstall(),+ Some(Command::Update) => unreachable!("handled above"),+ }+}++/// `kanzo update`: installs the latest release over this program, then restarts the+/// board's service, if there is one, so it runs the new version too.+fn update_kanzo() -> anyhow::Result<()> {+ let Some(latest) = update::latest(true) else {+ anyhow::bail!("can't reach GitHub to check for updates");+ };+ if !update::newer(&latest) {+ println!("Kanzo is up to date ({}).", update::CURRENT);+ return Ok(());+ }+ println!("Installing Kanzo {latest} (you have {})…", update::CURRENT);+ update::install().map_err(anyhow::Error::msg)?;+ if service::restart()? {+ println!("Updated to {latest}, and restarted the board.");+ } else {+ println!("Updated to {latest}.");}+ Ok(())}diff --git a/src/service.rs b/src/service.rsindex 8d1574a..767e191 100644--- a/src/service.rs+++ b/src/service.rs@@ -32,6 +32,19 @@ pub fn uninstall() -> Result<()> {}}+/// Restarts the service, if it's installed, so it runs a newly installed Kanzo; false+/// when there's none.+pub fn restart() -> Result<bool> {+ if cfg!(target_os = "macos") && plist_path()?.exists() {+ run("launchctl", &["kickstart", "-k", &format!("{}/{LABEL}", launchd_domain()?)])?;+ } else if cfg!(target_os = "linux") && unit_path()?.exists() {+ run("systemctl", &["--user", "restart", UNIT])?;+ } else {+ return Ok(false);+ }+ Ok(true)+}+fn home_dir() -> Result<PathBuf> {dirs::home_dir().context("cannot find your home folder")}diff --git a/src/store.rs b/src/store.rsindex 18e5f51..c7e2d35 100644--- a/src/store.rs+++ b/src/store.rs@@ -12,6 +12,12 @@ use std::time::Duration;use rusqlite::{Connection, OptionalExtension, Row, params};use serde::Serialize;+/// The oldest schema version whose Kanzo can still use a database at the latest one.+/// Adding a table or a column with a default leaves older versions working, so a board+/// synced from a newer Kanzo still opens in an older one. Raise it to the new version+/// only for a migration that older code can't live with, like a renamed column.+const COMPATIBLE_FROM: usize = 4;+/// Schema migrations, applied in order. Index + 1 is the `schema_version` they lead to.const MIGRATIONS: &[&str] = &[include_str!("schema.sql"),@@ -209,33 +215,37 @@ impl Store {/// Brings the schema up to date. Writes nothing when it already is, so starting/// `kanzo mcp` for every agent session costs no disk write.pub fn migrate(&self) -> Result<()> {- let current = self- .conn- .query_row("SELECT value FROM meta WHERE key = 'schema_version'", [], |r| r.get::<_, String>(0))- .optional()- .unwrap_or(None);- if current == Some(MIGRATIONS.len().to_string()) {+ let meta = |c: &Connection, key: &str| -> rusqlite::Result<Option<usize>> {+ Ok(c.query_row("SELECT value FROM meta WHERE key = ?1", [key], |r| r.get::<_, String>(0))+ .optional()?+ .and_then(|v| v.parse().ok()))+ };+ let latest = MIGRATIONS.len();+ let current =+ (meta(&self.conn, "schema_version").unwrap_or(None), meta(&self.conn, "compatible").unwrap_or(None));+ if current == (Some(latest), Some(COMPATIBLE_FROM)) {return Ok(());}self.write(|c| {c.execute("CREATE TABLE IF NOT EXISTS meta (key TEXT PRIMARY KEY, value TEXT NOT NULL)", [])?;- let version: usize = c- .query_row("SELECT value FROM meta WHERE key = 'schema_version'", [], |r| r.get::<_, String>(0))- .optional()?- .map_or(0, |v| v.parse().unwrap_or(0));- if version > MIGRATIONS.len() {- return Err(Error::Invalid(format!(- "kanzo.db has schema version {version}, newer than this kanzo supports ({}); update kanzo",- MIGRATIONS.len()- )));+ let version = meta(c, "schema_version")?.unwrap_or(0);+ if version > latest {+ // From a newer Kanzo, maybe synced from another machine: use it as it is+ // when this version can, without touching its schema.+ if meta(c, "compatible")?.is_some_and(|oldest| oldest <= latest) {+ return Ok(());+ }+ return Err(Error::Invalid(+ "this board was saved by a newer version of Kanzo; update this one with `kanzo update`".into(),+ ));}for sql in &MIGRATIONS[version..] {c.execute_batch(sql)?;}c.execute(- "INSERT INTO meta (key, value) VALUES ('schema_version', ?1)+ "INSERT INTO meta (key, value) VALUES ('schema_version', ?1), ('compatible', ?2)ON CONFLICT(key) DO UPDATE SET value = excluded.value",- [MIGRATIONS.len().to_string()],+ [latest.to_string(), COMPATIBLE_FROM.to_string()],)?;Ok(())})@@ -933,6 +943,30 @@ mod tests {assert_eq!(v, MIGRATIONS.len().to_string());}+ #[test]+ fn opens_a_board_from_a_newer_kanzo_when_it_can() {+ let (_dir, s) = store();+ let set = |version: usize, compatible: usize| {+ s.conn+ .execute_batch(&format!(+ "UPDATE meta SET value = '{version}' WHERE key = 'schema_version';+ UPDATE meta SET value = '{compatible}' WHERE key = 'compatible';"+ ))+ .unwrap();+ };+ let newer = MIGRATIONS.len() + 1;+ // A newer Kanzo only added things: this one goes on using the board, untouched.+ set(newer, MIGRATIONS.len());+ s.migrate().unwrap();+ s.create_project("api", "", None).unwrap();+ let v: String =+ s.conn.query_row("SELECT value FROM meta WHERE key = 'schema_version'", [], |r| r.get(0)).unwrap();+ assert_eq!(v, newer.to_string());+ // A change this version can't live with: it says how to update.+ set(newer, newer);+ assert!(s.migrate().unwrap_err().to_string().contains("kanzo update"));+ }+#[test]fn projects() {let (_dir, s) = store();