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
Search every project from a window, like ChatGPT
emanuele-emcf44a7e0f77d
diff --git a/README.md b/README.mdindex f844077..0cda480 100644--- a/README.md+++ b/README.md@@ -39,7 +39,7 @@ For macOS and Linux, including every Raspberry Pi. Or build it: `cargo install -Every command takes `--home <dir>` to use another data folder.-`n` adds a task, `/` searches, `Tab` moves to the description, `⌘↵` saves and closes, `Esc` cancels.+`n` adds a task, `/` or `⌘K` searches every project, `Tab` moves to the description, `⌘↵` saves and closes, `Esc` cancels.Paste or drop an image into a task or a comment to attach it, as in ChatGPT. Agents get its file path and can open it.diff --git a/src/app.js b/src/app.jsindex 8721043..9a793e7 100644--- a/src/app.js+++ b/src/app.js@@ -26,7 +26,6 @@ const state = {dragging: null, // id of the card being draggeddropped: false, // the current drag ended in a droplayout: "", // key of the rendered column layout- query: "", // search box textallDone: false, // show every card in the done columnmenu: null, // slug of the project whose "⋯" menu is open};@@ -226,7 +225,7 @@ async function loadBoard() {try {// The server leaves out older done tasks unless asked: the board does not show// them, and the done column only grows. Search needs them all.- const done = fullDone() ? "&done=all" : "";+ const done = state.allDone ? "&done=all" : "";const board = await api("GET", "/board?project=" + encodeURIComponent(state.project) + done);if (request !== boardRequest) return;state.board = board;@@ -243,10 +242,6 @@ async function loadBoard() {}}-function fullDone() {- return state.allDone || state.query.trim() !== "";-}-// The address is #project or #project/task-id, so a task can be linked to.function updateHash() {const hash = "#" + state.project + (state.task ? "/" + state.task : "");@@ -373,7 +368,7 @@ document.addEventListener("mousedown", (e) => {// A click outside the task panel closes it. Cards are left to open their own task,// and the project menu to do its job.document.addEventListener("mousedown", (e) => {- if (state.task && e.button === 0 && !e.target.closest("#panel, .card, .menu")) closeTask();+ if (state.task && e.button === 0 && !e.target.closest("#panel, .card, .menu, #search-dialog")) closeTask();});window.addEventListener("resize", closeMenu);window.addEventListener("blur", closeMenu);@@ -387,7 +382,6 @@ function renderHeader() {const p = currentProject();const { projects, tasks } = state.board;const header = $("#header");- $("#search-box").hidden = !projects.length;if (!projects.length) { header.replaceChildren(); return; }if (!p) {header.replaceChildren(el("h1", {}, "All projects"),@@ -445,15 +439,12 @@ function renderColumns() {// During a drag the DOM is being moved by hand; refresh once it ends.if (state.dragging) return;const all = state.project === "all";- const shown = tasks.filter(matches);- $("#search-note").textContent = !state.query.trim() ? ""- : shown.length ? `${shown.length} of ${tasks.length}` : "No matches";for (const status of statuses) {const col = columns.querySelector(`[data-status="${CSS.escape(status)}"]`);- const mine = shown.filter((t) => t.status === status);+ const mine = tasks.filter((t) => t.status === status);// Older done tasks the server left out (see loadBoard).const last = status === statuses[statuses.length - 1];- const hidden = last && !fullDone() ? state.board.done_hidden || 0 : 0;+ const hidden = last && !state.allDone ? state.board.done_hidden || 0 : 0;const count = mine.length + hidden;col.querySelector("h2 .count").textContent = count ? String(count) : "";const more = hidden@@ -474,14 +465,6 @@ function plainText(md) {.trim();}-// Every word of the search must appear in the task's id, title, description or project.-function matches(t) {- const words = state.query.toLowerCase().split(/\s+/).filter(Boolean);- if (!words.length) return true;- const text = `${key(t)} ${t.title} ${t.description} ${t.project} ${t.tags.join(" ")}`.toLowerCase();- return words.every((w) => text.includes(w));-}-function card(t, showProject) {const node = el("div", { class: "card" + (state.task === t.id ? " open" : ""), draggable: "true", "data-id": t.id,onclick: () => openTask(t.id) },@@ -892,21 +875,64 @@ $("#p-delete").addEventListener("click", async () => {// ---------- search -----------$("#search").addEventListener("input", (e) => {- const wasFull = fullDone();- state.query = e.target.value;- // Searching needs every done task; load them when a search starts.- if (fullDone() !== wasFull) loadBoard();- else if (state.board) renderColumns();-});+// The search window, as in ChatGPT: tasks of every project, found by the server, open+// ones first. Arrows pick, Enter opens, Esc closes. Without words it shows the latest changes.+let results = [], selected = 0, searchRequest = 0, searchTimer;++function openSearch() {+ closeMenu();+ $("#search-dialog").hidden = false;+ $("#search").value = "";+ $("#search").focus();+ runSearch();+}++function closeSearch() {+ $("#search-dialog").hidden = true;+}++async function runSearch() {+ const q = $("#search").value.trim();+ const request = ++searchRequest;+ try {+ const found = await api("GET", "/search?q=" + encodeURIComponent(q));+ if (request !== searchRequest) return;+ results = found;+ selected = 0;+ $("#search-results").replaceChildren(+ ...(results.length ? [el("div", { class: "label" }, q ? "Tasks" : "Recent")] : []),+ ...results.map((t, i) => el("button", { type: "button", class: "result" + (i === 0 ? " selected" : ""),+ onmousemove: () => select(i), onclick: () => pick(t) },+ el("span", { class: "dot", style: `background:${projectColor(t.project)}` }),+ el("span", { class: "title" }, t.title),+ el("span", { class: "meta" }, el("span", { class: "mono" }, key(t)), t.status))),+ ...(results.length ? [] : [el("div", { class: "note" }, q ? "No tasks match." : "No tasks yet.")]));+ } catch (err) { toast(err.message); }+}++function select(i) {+ const rows = $("#search-results").querySelectorAll(".result");+ if (!rows.length) return;+ selected = (i + rows.length) % rows.length;+ rows.forEach((r, j) => r.classList.toggle("selected", j === selected));+ rows[selected].scrollIntoView({ block: "nearest" });+}++// Opens the task, in its own project unless the board shows all of them.+function pick(t) {+ closeSearch();+ if (state.project !== "all" && state.project !== t.project) setProject(t.project);+ openTask(t.id);+}++$("#search-open").addEventListener("click", openSearch);+$("#search").addEventListener("input", () => { clearTimeout(searchTimer); searchTimer = setTimeout(runSearch, 120); });$("#search").addEventListener("keydown", (e) => {- if (e.key === "Escape") {- e.stopPropagation();- e.target.value = "";- e.target.dispatchEvent(new Event("input"));- e.target.blur();- }+ if (e.key === "ArrowDown" || e.key === "ArrowUp") { e.preventDefault(); select(selected + (e.key === "ArrowDown" ? 1 : -1)); }+ else if (e.key === "Enter" && results[selected]) { e.preventDefault(); pick(results[selected]); }+ else if (e.key === "Escape") { e.stopPropagation(); closeSearch(); }});+$("#search-dialog").addEventListener("mousedown", (e) => { if (e.target.id === "search-dialog") closeSearch(); });// ---------- keyboard, polling, start ----------@@ -914,9 +940,9 @@ document.addEventListener("keydown", (e) => {const typing = e.target.closest("input, textarea, select");if (e.key === "Escape" && state.menu) { closeMenu(); return; }if (e.key === "Escape" && state.task && !typing) closeTask();- if (e.key === "/" && !typing && !e.metaKey && !e.ctrlKey) {+ if ((e.key === "/" && !typing && !e.metaKey && !e.ctrlKey) || (e.key === "k" && (e.metaKey || e.ctrlKey))) {e.preventDefault();- $("#search").focus();+ openSearch();}if (e.key === "n" && !typing && !e.metaKey && !e.ctrlKey) {if ($("#columns .add")) { e.preventDefault(); newTask(); }diff --git a/src/index.html b/src/index.htmlindex 9275eb3..2e5afa9 100644--- a/src/index.html+++ b/src/index.html@@ -47,6 +47,8 @@ aside {}.brand { font-weight: 600; font-size: 17px; padding: 4px 10px 16px; letter-spacing: -.01em; display: flex; align-items: center; gap: 10px; }.brand img { width: 28px; height: 28px; margin: -4px 0; }+.brand .ghost { width: auto; margin: -6px 0 -6px auto; padding: 6px; color: var(--muted); }+.brand .ghost:hover, .brand .ghost:focus-visible { color: var(--text); }.nav { overflow-y: auto; flex: 1; display: flex; flex-direction: column; gap: 2px; }.ghost, .nav a {display: flex; align-items: center; gap: 10px; width: 100%; padding: 8px 10px; border: 0; border-radius: 10px;@@ -129,13 +131,6 @@ header h1 { font-size: 18px; margin: 0; font-weight: 600; letter-spacing: -.01emheader .sub { color: var(--muted); }header .sub a { color: inherit; text-decoration: none; }header .sub a:hover { color: var(--text); }-.search { display: flex; align-items: center; gap: 10px; }-.search .note { color: var(--faint); font-size: 12px; white-space: nowrap; }-.search label { position: relative; display: flex; align-items: center; }-.search label .icon { position: absolute; left: 12px; color: var(--faint); pointer-events: none; }-.search label .icon svg { width: 16px; height: 16px; }-.search input { width: 240px; padding: 7px 14px 7px 36px; border-radius: 99px; }-.search input::-webkit-search-cancel-button { display: none; }.columns {flex: 1; min-height: 0; display: grid; grid-auto-flow: column; grid-auto-columns: minmax(260px, 1fr);gap: 12px; padding: 0 24px 24px; overflow-x: auto;@@ -281,6 +276,30 @@ header .sub a:hover { color: var(--text); }.md blockquote { border-left: 3px solid var(--active); padding-left: 10px; color: var(--muted); }.md a { color: var(--link); }+/* The search window, as in ChatGPT. */+.search-dialog {+ position: fixed; inset: 0; z-index: 40; background: rgba(0,0,0,.45);+ display: flex; justify-content: center; align-items: flex-start; padding: 12vh 16px 16px;+}+.search-window {+ width: min(640px, 100%); max-height: 70vh; display: flex; flex-direction: column; overflow: hidden;+ background: var(--menu); border: 1px solid var(--border); border-radius: 18px; box-shadow: var(--shadow);+}+.search-field { display: flex; align-items: center; gap: 10px; padding: 14px 18px; border-bottom: 1px solid var(--border); }+.search-field .icon { color: var(--faint); }+.search-field input { flex: 1; min-width: 0; border: 0; background: none; font-size: 16px; }+.search-field input::-webkit-search-cancel-button { display: none; }+.results { overflow-y: auto; padding: 6px; }+.results .label { color: var(--faint); font-size: 12px; padding: 8px 12px 4px; }+.results .note { color: var(--faint); padding: 14px 12px; }+.result {+ display: flex; align-items: center; gap: 10px; width: 100%; padding: 10px 12px; border: 0; border-radius: 10px;+ background: none; text-align: left;+}+.result.selected { background: var(--hover); }+.result .title { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }+.result .meta { flex: none; display: flex; align-items: center; gap: 8px; color: var(--faint); font-size: 12px; }+.toast {position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); background: var(--text); color: var(--bg);padding: 9px 16px; border-radius: 99px; z-index: 20; box-shadow: var(--shadow); font-weight: 500;@@ -298,7 +317,6 @@ header .sub a:hover { color: var(--text); }#new-project-toggle, form.new-project { display: none; }.columns { grid-auto-columns: minmax(78vw, 1fr); padding: 0 12px 12px; }header { padding: 12px; }- .search, .search label, .search input { width: 100%; }}</style></head>@@ -307,6 +325,7 @@ header .sub a:hover { color: var(--text); }<div class="brand"><img src="/logo.png" alt="">Kanzo+ <button class="ghost" id="search-open" title="Search (/ or ⌘K)" aria-label="Search tasks"><span class="icon" data-icon="search"></span></button></div><button class="ghost" id="new-project-toggle"><span class="icon" data-icon="newProject"></span>New project</button><form class="new-project" id="new-project" hidden>@@ -325,10 +344,6 @@ header .sub a:hover { color: var(--text); }<main><header><div class="info" id="header"></div>- <div class="search" id="search-box" hidden>- <span class="note" id="search-note"></span>- <label><span class="icon" data-icon="search"></span><input class="field" id="search" type="search" placeholder="Search tasks" autocomplete="off" spellcheck="false" aria-label="Search tasks" title="Search (/)"></label>- </div></header><div class="columns" id="columns"></div></main>@@ -366,6 +381,13 @@ header .sub a:hover { color: var(--text); }</div></div>+<div class="search-dialog" id="search-dialog" hidden>+ <div class="search-window" role="dialog" aria-label="Search tasks">+ <label class="search-field"><span class="icon" data-icon="search"></span><input id="search" type="search" placeholder="Search tasks" autocomplete="off" spellcheck="false" aria-label="Search tasks"></label>+ <div class="results" id="search-results"></div>+ </div>+</div>+<div class="offline" id="offline" hidden>Board not reachable — is kanzo running?</div><script src="/app.js"></script>diff --git a/src/store.rs b/src/store.rsindex a859a85..87a3d14 100644--- a/src/store.rs+++ b/src/store.rs@@ -452,6 +452,30 @@ impl Store {Ok(tasks)}+ /// Tasks of any project whose key, title, description, tags or project hold every+ /// word of `query`: open ones first, then the most recently changed. An empty query+ /// gives the most recently changed tasks.+ pub fn search(&self, query: &str, limit: usize) -> Result<Vec<Task>> {+ let words: Vec<String> = query.split_whitespace().take(10).map(|w| w.to_lowercase()).collect();+ let mut sql = format!("{} WHERE 1", Self::TASK_SELECT);+ for i in 0..words.len() {+ sql.push_str(&format!(+ " AND lower(p.slug || '#' || t.id || ' ' || t.title || ' ' || t.description || ' ' || t.tags) \+ LIKE ?{} ESCAPE '\\'",+ i + 2+ ));+ }+ sql.push_str(&format!(" ORDER BY t.status = ?1, t.updated_at DESC, t.id DESC LIMIT {limit}"));+ let mut values: Vec<String> = vec![self.done_status().to_string()];+ for w in &words {+ let escaped = w.replace('\\', "\\\\").replace('%', "\\%").replace('_', "\\_");+ values.push(format!("%{escaped}%"));+ }+ let mut stmt = self.conn.prepare(&sql)?;+ let rows = stmt.query_map(rusqlite::params_from_iter(values.iter()), Self::task_row)?;+ Ok(rows.collect::<rusqlite::Result<_>>()?)+ }+pub fn get_task(&self, id: i64) -> Result<Task> {let sql = format!("{} WHERE t.id = ?1", Self::TASK_SELECT);self.conn@@ -919,6 +943,27 @@ mod tests {assert_eq!(s.link_repo("web", "me/api-docs").unwrap().repos, ["me/api-docs"]);}+ #[test]+ fn search() {+ let (_dir, s) = store();+ let api = s.create_project("api", "", None).unwrap();+ let web = s.create_project("web", "", None).unwrap();+ let login = s.create_task(api.id, "Fix login", "Users loop on /login").unwrap();+ let old = s.create_task(web.id, "Login page copy", "").unwrap();+ s.update_task(old.id, TaskPatch { status: Some("done".into()), ..Default::default() }).unwrap();+ let other = s.create_task(web.id, "Pricing 100%", "").unwrap();+ s.update_task(other.id, TaskPatch { tags: Some("ui".into()), ..Default::default() }).unwrap();+ let titles = |q: &str| s.search(q, 10).unwrap().into_iter().map(|t| t.title).collect::<Vec<_>>();+ assert_eq!(titles("LOGIN"), ["Fix login", "Login page copy"], "any project, open first, done too");+ assert_eq!(titles("login api"), ["Fix login"], "every word must match, the project too");+ assert_eq!(titles(&format!("web#{}", other.id)), ["Pricing 100%"], "by key");+ assert_eq!(titles("ui"), ["Pricing 100%"], "by tag");+ assert_eq!(titles("100%"), ["Pricing 100%"], "% is a plain character");+ assert!(titles("nothing-like-this").is_empty());+ assert_eq!(s.search("", 10).unwrap().len(), 3, "no words: the latest changes");+ assert_eq!(s.search("login", 1).unwrap()[0].id, login.id);+ }+#[test]fn images() {let (_dir, s) = store();diff --git a/src/web.rs b/src/web.rsindex 32d7257..f097bbc 100644--- a/src/web.rs+++ b/src/web.rs@@ -126,6 +126,7 @@ fn router(home: Home, guard: Guard, shutdown: CancellationToken) -> Router {.route("/api/ping", get(|| async { "kanzo" })).route("/api/changes", get(changes)).route("/api/board", get(board))+ .route("/api/search", get(search)).route("/api/projects", post(create_project)).route("/api/projects/{slug}", patch(update_project).delete(delete_project)).route("/api/projects/{slug}/repos", post(link_repo).delete(unlink_repo))@@ -296,6 +297,17 @@ async fn board(State(home): Shared, Query(q): Query<BoardQuery>) -> Response {.await}+#[derive(Deserialize)]+struct SearchQuery {+ #[serde(default)]+ q: String,+}++/// Tasks of every project matching the search, for the search window.+async fn search(State(home): Shared, Query(q): Query<SearchQuery>) -> Response {+ with_store(home, move |_, s| s.search(&q.q, 30)).await+}+#[derive(Deserialize)]struct NewProject {slug: String,