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.

Tag tasks

emanuele-em142e4bc15069
diff --git a/src/app.js b/src/app.js
index 61c963a..0f4b7fa 100644
--- a/src/app.js
+++ b/src/app.js
@@ -450,7 +450,7 @@ function plainText(md) {
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}`.toLowerCase();
+ const text = `${key(t)} ${t.title} ${t.description} ${t.project} ${t.tags.join(" ")}`.toLowerCase();
return words.every((w) => text.includes(w));
}
@@ -462,7 +462,8 @@ function card(t, showProject) {
// On "All projects" a dot in the project's colour tells the projects apart.
el("span", { class: "num", title: key(t) },
showProject ? el("span", { class: "dot", style: `background:${projectColor(t.project)}` }) : null, `#${t.id}`)),
- t.description ? el("div", { class: "desc" }, plainText(t.description)) : null);
+ t.description ? el("div", { class: "desc" }, plainText(t.description)) : null,
+ t.tags.length ? el("div", { class: "tags" }, t.tags.map((tag) => el("span", { class: "tag" }, tag))) : null);
node.addEventListener("dragstart", (e) => {
state.dragging = t.id;
e.dataTransfer.effectAllowed = "move";
@@ -636,7 +637,7 @@ async function refreshTask() {
$("#p-key").textContent = key(task);
// Never overwrite what is being typed or picked.
if (!$("#p-project").contains(document.activeElement)) renderProjectPick(task);
- for (const [field, value] of [[$("#p-title"), task.title], [$("#p-desc"), task.description]]) {
+ for (const [field, value] of [[$("#p-title"), task.title], [$("#p-desc"), task.description], [$("#p-tags"), task.tags.join(", ")]]) {
if (document.activeElement !== field) { field.value = value; fit(field); }
}
const status = $("#p-status");
@@ -684,6 +685,7 @@ function renderProjectPick(task) {
// Textareas grow with their text instead of scrolling.
function fit(t) {
+ if (t.tagName !== "TEXTAREA") return;
t.style.height = "auto";
t.style.height = t.scrollHeight + "px";
}
@@ -734,6 +736,19 @@ $("#p-desc").addEventListener("blur", (e) => {
$("#p-status").addEventListener("change", (e) => patchTask({ status: e.target.value }));
+// 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) => {
+ if (e.key === "Enter") { e.preventDefault(); e.target.blur(); }
+ else if (e.key === "Escape") cancelField(e, panelTask ? panelTask.tags.join(", ") : "");
+});
+$("#p-tags").addEventListener("blur", (e) => {
+ if (!panelTask) return;
+ const tags = cleanTags(e.target.value);
+ if (tags.join(",") !== panelTask.tags.join(",")) patchTask({ tags: tags.join(", ") });
+ else e.target.value = panelTask.tags.join(", ");
+});
+
$("#p-comment-form").addEventListener("submit", async (e) => {
e.preventDefault();
const body = $("#p-comment").value.trim();
diff --git a/src/export.rs b/src/export.rs
index 8a8311e..c14f040 100644
--- a/src/export.rs
+++ b/src/export.rs
@@ -36,6 +36,7 @@ struct TaskOut {
key: String,
title: String,
description: String,
+ tags: Vec<String>,
status: String,
created_at: String,
updated_at: String,
@@ -49,6 +50,7 @@ impl TaskOut {
id: task.id,
title: task.title,
description: task.description,
+ tags: task.tags,
status: task.status,
created_at: task.created_at,
updated_at: task.updated_at,
@@ -127,6 +129,9 @@ fn markdown(board: &Board) -> String {
short_time(&t.created_at),
short_time(&t.updated_at)
);
+ if !t.tags.is_empty() {
+ let _ = writeln!(md, "Tags: {}.", t.tags.join(", "));
+ }
if !t.description.is_empty() {
let _ = write!(md, "\n{}\n", t.description);
}
diff --git a/src/index.html b/src/index.html
index 9cfc25b..ff0b6e9 100644
--- a/src/index.html
+++ b/src/index.html
@@ -153,6 +153,7 @@ header .sub a:hover { color: var(--text); }
color: var(--faint); font-size: 12px; font-variant-numeric: tabular-nums;
}
.card .num .dot { width: 6px; height: 6px; }
+.card .tags { display: flex; flex-wrap: wrap; gap: 4px; margin-top: 6px; }
.card .desc {
margin-top: 2px; color: var(--muted); font-size: 13px;
white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
@@ -315,6 +316,7 @@ header .sub a:hover { color: var(--text); }
<textarea class="inline title-input" id="p-title" rows="1" spellcheck="false" placeholder="Task title"></textarea>
<div class="props">
Status <span><select class="field" id="p-status"></select></span>
+ Tags <span><input class="inline" id="p-tags" placeholder="Add tags, like bug, ui" autocomplete="off" spellcheck="false"></span>
Created <span id="p-created"></span>
Updated <span id="p-updated"></span>
</div>
diff --git a/src/mcp.rs b/src/mcp.rs
index f6fa7e6..d59340b 100644
--- a/src/mcp.rs
+++ b/src/mcp.rs
@@ -178,6 +178,8 @@ struct CreateTaskArgs {
description: Option<String>,
/// Project slug. Defaults to the project of the current repo.
project: Option<String>,
+ /// Comma-separated, like "bug, ui".
+ tags: Option<String>,
}
#[derive(Deserialize, JsonSchema)]
@@ -190,6 +192,8 @@ struct UpdateTaskArgs {
description: Option<String>,
/// New column, like doing, review or done. The task goes to the bottom of it.
status: Option<String>,
+ /// Comma-separated; replaces all tags, and "" clears them.
+ tags: Option<String>,
}
#[derive(Deserialize, JsonSchema)]
@@ -341,13 +345,16 @@ impl Kanzo {
Ok(self
.run(move |ctx, store| {
let project = ctx.project(store, args.project.as_deref())?;
- let t = store.create_task(project.id, &args.title, args.description.as_deref().unwrap_or(""))?;
+ let mut t = store.create_task(project.id, &args.title, args.description.as_deref().unwrap_or(""))?;
+ if args.tags.is_some() {
+ t = store.update_task(t.id, TaskPatch { tags: args.tags, ..Default::default() })?;
+ }
Ok(format!("Created {} in {}: {}", t.key(), t.status, t.title))
})
.await)
}
- #[tool(description = "Change a task's title, description or status. Only the fields you pass change.")]
+ #[tool(description = "Change a task's title, description, status or tags. Only the fields you pass change.")]
async fn update_task(&self, Parameters(args): Parameters<UpdateTaskArgs>) -> Result<CallToolResult, ErrorData> {
Ok(self
.run(move |_, store| {
@@ -355,7 +362,13 @@ impl Kanzo {
let status = args.status.map(|s| s.trim().to_ascii_lowercase());
let after = store.update_task(
before.id,
- TaskPatch { title: args.title, description: args.description, status, project_id: None },
+ TaskPatch {
+ title: args.title,
+ description: args.description,
+ status,
+ tags: args.tags,
+ project_id: None,
+ },
)?;
let moved = if before.status != after.status {
format!(", {} -> {}", before.status, after.status)
@@ -448,14 +461,19 @@ fn task_line(t: &Task) -> String {
1 => " (1 comment)".into(),
n => format!(" ({n} comments)"),
};
- format!("{} [{}] {}{comments}", t.key(), t.status, t.title)
+ format!("{} [{}] {}{}{comments}", t.key(), t.status, t.title, tag_list(t))
+}
+
+/// ` {bug, ui}`, or nothing without tags.
+fn tag_list(t: &Task) -> String {
+ if t.tags.is_empty() { String::new() } else { format!(" {{{}}}", t.tags.join(", ")) }
}
fn task_detail(t: &Task, comments: &[Comment]) -> String {
let (created, updated) = (short_time(&t.created_at), short_time(&t.updated_at));
// The update time only when it says something the creation time does not.
let updated = if updated == created { String::new() } else { format!(", updated {updated}") };
- let mut out = format!("{} {}\nstatus: {}, created {created}{updated}\n", t.key(), t.title, t.status);
+ let mut out = format!("{} {}{}\nstatus: {}, created {created}{updated}\n", t.key(), t.title, tag_list(t), t.status);
if !t.description.is_empty() {
out.push('\n');
out.push_str(&t.description);
diff --git a/src/store.rs b/src/store.rs
index c70506b..e9f0a77 100644
--- a/src/store.rs
+++ b/src/store.rs
@@ -17,6 +17,8 @@ const MIGRATIONS: &[&str] = &[
include_str!("schema.sql"),
// 2: a colour picked for the project; NULL leaves the board to choose one.
"ALTER TABLE projects ADD COLUMN color TEXT;",
+ // 3: a task's tags, comma-separated (see `clean_tags`).
+ "ALTER TABLE tasks ADD COLUMN tags TEXT NOT NULL DEFAULT '';",
];
/// The colours a project can be given; the board maps each name to a shade.
@@ -79,6 +81,8 @@ pub struct Task {
pub project: String,
pub title: String,
pub description: String,
+ /// Lowercase, without duplicates, in the order they were given.
+ pub tags: Vec<String>,
pub status: String,
pub position: f64,
pub created_at: String,
@@ -110,6 +114,8 @@ pub struct TaskPatch {
pub status: Option<String>,
/// Moves the task to this project (by id).
pub project_id: Option<i64>,
+ /// Comma-separated; replaces all the tags, and an empty string clears them.
+ pub tags: Option<String>,
}
pub struct Store {
@@ -337,7 +343,7 @@ impl Store {
// Tasks
const TASK_SELECT: &str = "SELECT t.id, p.slug, t.title, t.description, t.status, t.position,
- t.created_at, t.updated_at, (SELECT count(*) FROM comments c WHERE c.task_id = t.id)
+ t.created_at, t.updated_at, (SELECT count(*) FROM comments c WHERE c.task_id = t.id), t.tags
FROM tasks t JOIN projects p ON p.id = t.project_id";
fn task_row(r: &Row) -> rusqlite::Result<Task> {
@@ -346,6 +352,7 @@ impl Store {
project: r.get(1)?,
title: r.get(2)?,
description: r.get(3)?,
+ tags: r.get::<_, String>(9)?.split(',').filter(|t| !t.is_empty()).map(String::from).collect(),
status: r.get(4)?,
position: r.get(5)?,
created_at: r.get(6)?,
@@ -440,6 +447,12 @@ impl Store {
params![p, id],
)?;
}
+ if let Some(t) = &patch.tags {
+ c.execute(
+ &format!("UPDATE tasks SET tags = ?1, updated_at = {NOW} WHERE id = ?2"),
+ params![clean_tags(t).join(","), id],
+ )?;
+ }
if let Some(d) = &patch.description {
c.execute(
&format!("UPDATE tasks SET description = ?1, updated_at = {NOW} WHERE id = ?2"),
@@ -610,6 +623,18 @@ fn valid_slug(s: &str) -> bool {
&& b.iter().all(|c| c.is_ascii_lowercase() || c.is_ascii_digit() || *c == b'-')
}
+/// `" Bug, UI,bug ,, needs review"` -> `["bug", "ui", "needs review"]`.
+pub fn clean_tags(input: &str) -> Vec<String> {
+ let mut tags: Vec<String> = Vec::new();
+ for tag in input.split(',') {
+ let tag = tag.split_whitespace().collect::<Vec<_>>().join(" ").to_lowercase();
+ if !tag.is_empty() && !tags.contains(&tag) {
+ tags.push(tag);
+ }
+ }
+ tags
+}
+
fn clean_title(title: &str) -> Result<String> {
let title = title.split_whitespace().collect::<Vec<_>>().join(" ");
if title.is_empty() {
@@ -727,6 +752,12 @@ mod tests {
assert_eq!(comments.iter().map(|c| c.author.as_str()).collect::<Vec<_>>(), ["claude-code", "me"]);
assert!(s.add_comment(t.id, "me", " ").is_err());
assert_eq!(s.get_task(t.id).unwrap().comments, 2);
+ let tagged =
+ s.update_task(t.id, TaskPatch { tags: Some(" Bug, UI,bug ,, needs review".into()), ..Default::default() });
+ assert_eq!(tagged.unwrap().tags, ["bug", "ui", "needs review"]);
+ assert!(
+ s.update_task(t.id, TaskPatch { tags: Some(" , ".into()), ..Default::default() }).unwrap().tags.is_empty()
+ );
let gone = s.add_comment(t.id, "me", "typo").unwrap();
assert_eq!(s.delete_comment(gone.id).unwrap().body, "typo");
assert!(s.delete_comment(gone.id).is_err());
diff --git a/src/web.rs b/src/web.rs
index 749c7bc..c25d8dd 100644
--- a/src/web.rs
+++ b/src/web.rs
@@ -342,12 +342,16 @@ struct Patch {
description: Option<String>,
status: Option<String>,
project: Option<String>,
+ tags: Option<String>,
}
async fn update_task(State(home): Shared, Path(id): Path<i64>, Json(p): Json<Patch>) -> Response {
with_store(home, move |_, s| {
let project_id = p.project.map(|slug| s.find_project(&slug)).transpose()?.map(|p| p.id);
- s.update_task(id, TaskPatch { title: p.title, description: p.description, status: p.status, project_id })
+ s.update_task(
+ id,
+ TaskPatch { title: p.title, description: p.description, status: p.status, project_id, tags: p.tags },
+ )
})
.await
}