Skip to content

armgit / kanzo

Public Imported from GitHub
0

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.

Select several tasks and change them together

emanuele-em5e57ff94352f
diff --git a/README.md b/README.md
index 332607f..1dd7d21 100644
--- a/README.md
+++ b/README.md
@@ -60,7 +60,7 @@ kanzo
The board opens at http://localhost:4242. That's all the setup there is: the first run creates `~/kanzo`, and the whole board lives in it.
-`n` adds a task, `/` or `⌘K` searches every project, `f` filters the board and `↵` keeps the filter, `Tab` moves to the description, `⌘↵` saves and closes. `Esc` leaves a description or tags with what you typed saved, and cancels other fields. Mark a task Human and agents leave it to you; the person icon shows only those. Paste or drop an image into a task or a comment to attach it. Give a task a URL, like its pull request on any site, and click the link on its card to open it; agents set it with `url`. A link to a file in a description or comment, `[name](file:///path)`, opens in your editor. When a new version is out, the sidebar offers it: one click installs it.
+`n` adds a task, `/` or `⌘K` searches every project, `⌘`-click or a drag on empty board space selects tasks to move, tag or delete together, `f` filters the board and `↵` keeps the filter, `Tab` moves to the description, `⌘↵` saves and closes. `Esc` leaves a description or tags with what you typed saved, and cancels other fields. Mark a task Human and agents leave it to you; the person icon shows only those. Paste or drop an image into a task or a comment to attach it. Give a task a URL, like its pull request on any site, and click the link on its card to open it; agents set it with `url`. A link to a file in a description or comment, `[name](file:///path)`, opens in your editor. When a new version is out, the sidebar offers it: one click installs it.
## Connect your agents
diff --git a/src/app.js b/src/app.js
index e12a810..9d3b7ba 100644
--- a/src/app.js
+++ b/src/app.js
@@ -29,6 +29,8 @@ const state = {
menu: null,
net: null,
guests: null,
+ selected: new Set(),
+ sweeping: false,
};
async function api(method, path, body) {
@@ -543,10 +545,11 @@ function renderColumns() {
return col;
}));
showCollapsed();
+ $("#bulk-status").replaceChildren(el("option", { value: "", hidden: true }, "Move to…"), ...statuses.map((s) => el("option", { value: s }, s)));
}
// During a drag the DOM is being moved by hand; refresh once it ends.
- if (state.dragging) return;
+ if (state.dragging || state.sweeping) return;
const all = state.project === "all";
const humanOnly = isHumanOnly();
const query = filterQuery();
@@ -567,8 +570,102 @@ function renderColumns() {
col.querySelector(".cards").replaceChildren(...[more].filter(Boolean), ...mine.map((t) => card(t, all)));
}
highlight("filter", columns, wordsOf(query));
+ for (const id of [...state.selected]) {
+ if (!columns.querySelector(`.card[data-id="${id}"]`)) state.selected.delete(id);
+ }
+ showSelection();
+}
+
+function showSelection() {
+ $("#bulk").hidden = !state.selected.size;
+ $("#bulk-count").textContent = `${state.selected.size} selected`;
+}
+
+function setSelected(id, on) {
+ if (on) state.selected.add(id); else state.selected.delete(id);
+ document.querySelector(`[data-id="${id}"]`)?.classList.toggle("selected", on);
+}
+
+function clearSelection() {
+ state.selected.forEach((id) => setSelected(id, false));
+ showSelection();
+}
+
+// Closes the panel: one or the other, so the bar can't cover it.
+function toggleSelected(id) {
+ if (state.task) closeTask();
+ setSelected(id, !state.selected.has(id));
+ showSelection();
+}
+
+// Drag on empty board space to select, with ⌘ to add to what's selected. Cards are measured once, when
+// the drag starts, so moving the mouse never forces a layout.
+function sweep(down) {
+ const marquee = el("div", { class: "marquee" });
+ const kept = new Set(down.metaKey || down.ctrlKey ? state.selected : []);
+ let cards, x, y, frame = 0;
+ const paint = () => {
+ frame = 0;
+ const x1 = Math.min(down.clientX, x), x2 = Math.max(down.clientX, x), y1 = Math.min(down.clientY, y), y2 = Math.max(down.clientY, y);
+ marquee.style.cssText = `left:${x1}px;top:${y1}px;width:${x2 - x1}px;height:${y2 - y1}px`;
+ for (const { id, r, list } of cards) {
+ // A card scrolled out of its column can't be under the box.
+ const hit = r.right > x1 && r.left < x2 && r.bottom > Math.max(y1, list.top) && r.top < Math.min(y2, list.bottom);
+ if ((hit || kept.has(id)) !== state.selected.has(id)) setSelected(id, !state.selected.has(id));
+ }
+ showSelection();
+ };
+ const move = (e) => {
+ x = e.clientX; y = e.clientY;
+ if (!cards) {
+ if (Math.hypot(x - down.clientX, y - down.clientY) < 4) return;
+ state.sweeping = true;
+ document.body.append(marquee);
+ cards = [...$("#columns").querySelectorAll(".column:not(.collapsed) .card")].map((n) =>
+ ({ id: +n.dataset.id, r: n.getBoundingClientRect(), list: n.parentNode.getBoundingClientRect() }));
+ }
+ if (!frame) frame = requestAnimationFrame(paint);
+ };
+ const up = () => {
+ cancelAnimationFrame(frame);
+ document.removeEventListener("mousemove", move);
+ document.removeEventListener("mouseup", up);
+ marquee.remove();
+ state.sweeping = false;
+ if (cards) renderColumns();
+ else if (!kept.size) clearSelection();
+ };
+ document.addEventListener("mousemove", move);
+ document.addEventListener("mouseup", up);
}
+$("#columns").addEventListener("mousedown", (e) => {
+ const onScrollbar = e.offsetX > e.target.clientWidth || e.offsetY > e.target.clientHeight;
+ if (e.button || onScrollbar || e.target.closest(".card, button, a, .collapsed")) return;
+ e.preventDefault();
+ sweep(e);
+});
+
+async function changeSelected(change) {
+ const ids = state.board.tasks.filter((t) => state.selected.has(t.id)).map((t) => t.id);
+ try { await api("POST", "/tasks/bulk", { ids, ...change }); } catch (err) { toast(err.message); }
+ loadBoard();
+}
+
+$("#bulk").addEventListener("keydown", (e) => {
+ const { name, value } = e.target;
+ if (e.key === "Escape") { e.stopPropagation(); e.target.blur(); clearSelection(); }
+ else if (e.key === "Enter" && name && value.trim()) { changeSelected({ [name]: value }); e.target.value = ""; }
+});
+$("#bulk-status").addEventListener("change", (e) => {
+ changeSelected({ status: e.target.value });
+ e.target.value = "";
+});
+$("#bulk-delete").addEventListener("click", () => {
+ if (confirm(`Delete ${plural(state.selected.size, "task")}, with comments and images? This cannot be undone.`)) changeSelected({ delete: true });
+});
+$("#bulk-clear").addEventListener("click", clearSelection);
+
function savedFilters() {
try { return JSON.parse(localStorageGet("kanzo.filters")) || []; } catch { return []; }
}
@@ -730,8 +827,9 @@ function plainText(md) {
}
function card(t, showProject) {
- const node = el("div", { class: "card" + (state.task === t.id ? " open" : "") + (t.waiting_on ? " waiting" : ""), draggable: "true", "data-id": t.id,
- onclick: () => openTask(t.id) },
+ const node = el("div", { class: "card" + (state.task === t.id ? " open" : "") + (t.waiting_on ? " waiting" : "") + (state.selected.has(t.id) ? " selected" : ""),
+ draggable: "true", "data-id": t.id,
+ onclick: (e) => { if (e.metaKey || e.ctrlKey) toggleSelected(t.id); else openTask(t.id); } },
el("div", { class: "head" },
el("div", { class: "title" }, t.title),
t.human ? el("span", { class: "human-mark", title: "Human task: agents skip it" }, icon("human")) : null,
@@ -873,6 +971,7 @@ const taskLink = (t) => el("button", { type: "button", class: "tag", title: key(
statusIcon(t.status), el("span", {}, t.title));
async function openTask(id) {
+ clearSelection();
leavePanelField();
if (fresh !== id) dropFresh();
state.task = id;
@@ -1272,6 +1371,7 @@ document.addEventListener("keydown", (e) => {
const plain = !typing && !e.metaKey && !e.ctrlKey;
if (e.key === "Escape" && state.menu) { closeMenu(); return; }
if (e.key === "Escape" && state.task && !typing) closeTask();
+ if (e.key === "Escape" && !typing) clearSelection();
if ((e.key === "/" && plain) || (e.key === "k" && (e.metaKey || e.ctrlKey))) {
e.preventDefault();
openSearch();
diff --git a/src/index.html b/src/index.html
index 82e870c..5385103 100644
--- a/src/index.html
+++ b/src/index.html
@@ -73,7 +73,7 @@ aside {
.nav .item.renaming { display: flex; align-items: center; gap: 10px; padding: 3px 6px 3px 10px; }
.nav .item.renaming .field { padding: 5px 8px; border-radius: 8px; }
@media (hover: none) { .nav .more { display: block; } .nav .item .count { visibility: hidden; } }
-.menu {
+.menu, .bulk {
position: fixed; z-index: 30; min-width: 190px; padding: 6px; background: var(--menu);
border: 1px solid var(--border); border-radius: 16px; box-shadow: var(--shadow);
}
@@ -217,6 +217,11 @@ header .repo-link .icon svg { width: 14px; height: 14px; }
.card:hover { background: var(--card-hover); }
.card.open { background: var(--active); }
html:not([data-hide~="waiting"]) .card.waiting:not(:hover) { opacity: .6; }
+.card.selected { box-shadow: inset 0 0 0 2px var(--link); }
+.marquee { position: fixed; z-index: 9; pointer-events: none; background: color-mix(in srgb, var(--link) 15%, transparent); }
+.bulk { bottom: 20px; left: 50%; transform: translateX(-50%); display: flex; flex-wrap: wrap; align-items: center; gap: 8px; width: max-content; max-width: calc(100vw - 16px); }
+.bulk .field { width: 120px; padding: 5px 12px; }
+.bulk select { text-transform: capitalize; }
.card.dragging { opacity: .4; }
.card .head { display: flex; align-items: flex-start; gap: 10px; }
.card .title { overflow-wrap: anywhere; flex: 1; min-width: 0; }
@@ -270,9 +275,9 @@ html:not([data-hide~="waiting"]) .card.waiting:not(:hover) { opacity: .6; }
.panel .top { display: flex; align-items: center; gap: 8px; padding: 14px 16px 6px 20px; }
.panel .top .key { color: var(--muted); }
.panel .top .spacer { flex: 1; }
-.panel .top .ghost { width: auto; padding: 6px; color: var(--muted); }
-.panel .top .ghost:hover { color: var(--text); }
-.panel .top .ghost.danger:hover { color: var(--danger); background: var(--danger-bg); }
+.panel .top .ghost, .bulk .ghost { width: auto; padding: 6px; color: var(--muted); }
+.panel .top .ghost:hover, .bulk .ghost:hover { color: var(--text); }
+.panel .top .ghost.danger:hover, .bulk .danger:hover { color: var(--danger); background: var(--danger-bg); }
.panel .project-pick select {
appearance: none; -webkit-appearance: none; border: 0; background: none; padding: 0; margin: 0;
font-size: inherit; color: inherit; cursor: pointer; field-sizing: content;
@@ -507,6 +512,15 @@ label.setting { cursor: pointer; }
<div class="columns" id="columns"></div>
</main>
+<div class="bulk" id="bulk" hidden>
+ <span id="bulk-count"></span>
+ <select class="field" id="bulk-status" aria-label="Move to"></select>
+ <input class="field" name="add_tags" placeholder="Add tags" autocomplete="off">
+ <input class="field" name="remove_tags" placeholder="Remove tags" autocomplete="off">
+ <button class="ghost danger" id="bulk-delete" title="Delete" aria-label="Delete"><span class="icon" data-icon="trash"></span></button>
+ <button class="ghost" id="bulk-clear" title="Clear (Esc)" aria-label="Clear"><span class="icon" data-icon="close"></span></button>
+</div>
+
<div class="panel" id="panel" aria-hidden="true">
<div class="top">
<span class="key mono" id="p-key"></span>
diff --git a/src/store.rs b/src/store.rs
index 7eea117..5b9f580 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -737,6 +737,41 @@ impl Store {
self.get_task(id)
}
+ /// In one write: all or nothing, and about 60 times faster than one write per task. Tags are
+ /// added and removed, not replaced, so each task keeps its others.
+ pub fn update_tasks(&self, ids: &[i64], status: Option<&str>, add_tags: &str, remove_tags: &str) -> Result<()> {
+ if let Some(s) = status {
+ self.check_status(s)?;
+ }
+ let (add, remove) = (clean_tags(add_tags), clean_tags(remove_tags));
+ self.write(|c| {
+ for &id in ids {
+ let task = self.get_task(id)?;
+ let mut tags = task.tags.clone();
+ tags.retain(|t| !remove.contains(t));
+ for tag in &add {
+ if !tags.contains(tag) {
+ tags.push(tag.clone());
+ }
+ }
+ if tags != task.tags {
+ c.execute(
+ &format!("UPDATE tasks SET tags = ?1, updated_at = {NOW} WHERE id = ?2"),
+ params![tags.join(","), id],
+ )?;
+ }
+ if let Some(s) = status.filter(|s| *s != task.status) {
+ let position = Self::end_of_column(c, s, id)?;
+ c.execute(
+ &format!("UPDATE tasks SET status = ?1, position = ?2, updated_at = {NOW} WHERE id = ?3"),
+ params![s, position, id],
+ )?;
+ }
+ }
+ Ok(())
+ })
+ }
+
pub fn move_task(&self, id: i64, status: &str, before: Option<i64>) -> Result<Task> {
self.check_status(status)?;
self.write(|c| {
@@ -850,6 +885,15 @@ impl Store {
Ok(task)
}
+ pub fn delete_tasks(&self, ids: &[i64]) -> Result<()> {
+ self.write(|c| {
+ for id in ids {
+ c.execute("DELETE FROM tasks WHERE id = ?1", [id])?;
+ }
+ Ok(())
+ })
+ }
+
pub fn list_comments(&self, task_id: i64) -> Result<Vec<Comment>> {
let mut stmt = self.conn.prepare_cached(&format!("{} WHERE task_id = ?1 ORDER BY id", Self::COMMENT_SELECT))?;
let rows = stmt.query_map([task_id], Self::comment_row)?;
@@ -932,6 +976,13 @@ impl Store {
pub fn image_files(&self, of: ImagesOf) -> Result<Vec<String>> {
let (sql, id) = match of {
+ ImagesOf::Tasks(ids) => {
+ let mut files = Vec::new();
+ for id in ids {
+ files.extend(self.image_files(ImagesOf::Task(id))?);
+ }
+ return Ok(files);
+ }
ImagesOf::Image(id) => ("SELECT file FROM images WHERE id = ?1", id),
ImagesOf::Comment(id) => ("SELECT DISTINCT file FROM images WHERE comment_id = ?1", id),
ImagesOf::Task(id) => ("SELECT DISTINCT file FROM images WHERE task_id = ?1", id),
@@ -960,6 +1011,7 @@ pub enum ImagesOf {
Image(i64),
Comment(i64),
Task(i64),
+ Tasks(Vec<i64>),
Project(i64),
}
@@ -1366,6 +1418,40 @@ mod tests {
assert_eq!(s.search_for_agent("is:waiting").unwrap().len(), 0, "a hidden property finds nothing");
}
+ #[test]
+ fn changes_many_tasks_at_once_or_not_at_all() {
+ let (_dir, s) = store();
+ let p = s.create_project("api", "", None).unwrap();
+ let task = |title, tags: &str| {
+ let tags = Some(tags.to_string());
+ s.create_task_in(p.id, title, TaskPatch { tags, ..Default::default() }).unwrap().id
+ };
+ let (a, b, c) = (task("a", "bug, ui"), task("b", "ui"), task("c", "keep"));
+
+ s.update_tasks(&[a, b], Some("doing"), "New, bug", "ui").unwrap();
+ let tags = |id| s.get_task(id).unwrap().tags;
+ assert_eq!(
+ (tags(a), tags(b), tags(c)),
+ (vec!["bug".into(), "new".into()], vec!["new".into(), "bug".into()], vec!["keep".into()])
+ );
+ assert_eq!(titles(&s.list_tasks(None, Some("doing")).unwrap()), ["a", "b"], "they keep their order");
+
+ let before = s.changes().unwrap();
+ assert!(s.update_tasks(&[c, 999], Some("done"), "x", "").is_err());
+ assert!(s.update_tasks(&[c], Some("nope"), "", "").is_err());
+ assert_eq!(
+ (s.get_task(c).unwrap().status.as_str(), tags(c), s.changes().unwrap()),
+ ("todo", vec!["keep".into()], before)
+ );
+
+ let before = s.get_task(a).unwrap();
+ s.update_tasks(&[a], Some("doing"), "bug", "absent").unwrap();
+ assert_eq!(s.get_task(a).unwrap().position, before.position, "nothing to change moves nothing");
+
+ s.delete_tasks(&[a, 999, b]).unwrap();
+ assert_eq!(titles(&s.list_tasks(None, None).unwrap()), ["c"]);
+ }
+
#[test]
fn keeps_only_the_newest_done_tasks() {
let (_dir, s) = store();
diff --git a/src/web.rs b/src/web.rs
index 2fa5a33..f488dc0 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -156,6 +156,7 @@ fn router(home: Home, guard: Arc<Guard>, shutdown: CancellationToken) -> Router
.route("/api/projects/{slug}", patch(update_project).delete(delete_project))
.route("/api/projects/{slug}/repos", post(link_repo).delete(unlink_repo))
.route("/api/tasks", post(create_task))
+ .route("/api/tasks/bulk", post(bulk_tasks))
.route("/api/tasks/{id}", get(get_task).patch(update_task).delete(delete_task))
.route("/api/tasks/{id}/move", post(move_task))
.route("/api/tasks/{id}/comments", post(add_comment))
@@ -595,6 +596,29 @@ async fn delete_task(State(home): Shared, Path(id): Path<i64>) -> Response {
with_store(home, move |h, s| h.deleting_images(s, ImagesOf::Task(id), || s.delete_task(id))).await
}
+#[derive(Deserialize)]
+struct Bulk {
+ ids: Vec<i64>,
+ status: Option<String>,
+ #[serde(default)]
+ add_tags: String,
+ #[serde(default)]
+ remove_tags: String,
+ #[serde(default)]
+ delete: bool,
+}
+
+async fn bulk_tasks(State(home): Shared, Json(b): Json<Bulk>) -> Response {
+ with_store(home, move |h, s| {
+ if b.delete {
+ h.deleting_images(s, ImagesOf::Tasks(b.ids.clone()), || s.delete_tasks(&b.ids))
+ } else {
+ s.update_tasks(&b.ids, b.status.as_deref(), &b.add_tags, &b.remove_tags)
+ }
+ })
+ .await
+}
+
#[derive(Deserialize)]
struct NewComment {
#[serde(default)]