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
Link pull requests to tasks and open them from the board (#26)
Joffrey8f55d3ad90b9
diff --git a/README.md b/README.mdindex 51523d8..5a32b48 100644--- a/README.md+++ b/README.md@@ -58,7 +58,7 @@ kanzoThe 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` cancels. 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. When a new version is out, the sidebar offers it: one click installs 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` cancels. 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`. When a new version is out, the sidebar offers it: one click installs it.## Connect your agents@@ -188,6 +188,8 @@ listen = "127.0.0.1" # sharing opens the board to your network; "0.0.0.0" keepmcp_http = true # MCP at /mcp```+Settings on the board lists each task's properties, like tags or comments. Turn one off to hide it there and leave it out of what agents get; nothing is deleted.+## Small and fast| | |diff --git a/src/app.js b/src/app.jsindex f77a081..3f27f96 100644--- a/src/app.js+++ b/src/app.js@@ -81,6 +81,7 @@ const ICONS = {check: '<path d="M20 6 9 17l-5-5"/>',copy: '<rect width="14" height="14" x="8" y="8" rx="2"/><path d="M4 16a2 2 0 0 1-2-2V4a2 2 0 0 1 2-2h10a2 2 0 0 1 2 2"/>',human: '<circle cx="12" cy="8" r="4"/><path d="M5 21v-1a6 6 0 0 1 6-6h2a6 6 0 0 1 6 6v1"/>',+ url: '<path d="M10 13a5 5 0 0 0 7.54.54l3-3a5 5 0 0 0-7.07-7.07l-1.72 1.71"/><path d="M14 11a5 5 0 0 0-7.54-.54l-3 3a5 5 0 0 0 7.07 7.07l1.71-1.71"/>',github: '<path d="M15 22v-4a4.8 4.8 0 0 0-1-3.5c3 0 6-2 6-5.5.1-1.3-.3-2.5-1-3.5.3-1.2.3-2.4 0-3.5 0 0-1 0-3 1.5a12 12 0 0 0-8 0C6 2 5 2 5 2c-.3 1.2-.3 2.4 0 3.5A5.4 5.4 0 0 0 4 9c0 3.5 3 5.5 6 5.5-.4.5-.7 1-.8 1.7-.2.6-.3 1.2-.2 1.8v4"/><path d="M9 18c-4.5 2-5-2-7-2"/>',sync: '<path d="M12 13v8"/><path d="M4 14.9A7 7 0 1 1 15.7 8h1.8a4.5 4.5 0 0 1 2.5 8.2"/><path d="m8 17 4-4 4 4"/>',collapse: '<path d="m13 17 5-5-5-5M6 17l5-5-5-5"/>',@@ -289,6 +290,7 @@ async function loadBoard() {+ (q ? "&q=" + encodeURIComponent(q) : ""));if (request !== boardRequest) return;state.board = board;+ document.documentElement.dataset.hide = (board.hidden_properties || []).join(" ");state.changes = board.changes;$("#offline").hidden = true;render();@@ -476,7 +478,7 @@ function renderHeader() {const { projects, tasks } = state.board;const header = $("#header");$("#new-task").hidden = !projects.length;- $("#human-only").hidden = !projects.length;+ $("#human-only").hidden = !projects.length || isPropertyHidden("human");$("#filter").hidden = !projects.length;$("#filters").replaceChildren(...(projects.length ? savedFilters() : []).map((f, i) =>el("span", { class: "chip" }, f,@@ -600,15 +602,29 @@ function highlight(name, root, words) {CSS.highlights.set(name, new Highlight(...ranges));}-function summary(t) {+function summary(t, link = null) {+ const chips = [...(link ? [link] : []), ...(isPropertyHidden("tags") ? [] : t.tags.map((tag) => el("span", { class: "tag" }, tag)))];return [t.description ? el("span", { class: "desc" }, plainText(t.description)) : null,- t.tags.length ? el("span", { class: "tags" }, t.tags.map((tag) => el("span", { class: "tag" }, tag))) : null,+ chips.length ? el("span", { class: "tags" }, chips) : null,];}+// Only on cards: search rows are buttons, and a link can't sit inside one.+function urlChip(t) {+ if (!t.url || isPropertyHidden("url")) return null;+ return el("a", { class: "tag url", href: t.url, target: "_blank", rel: "noopener", title: t.url, draggable: "false",+ onclick: (e) => e.stopPropagation() },+ icon("url"), t.url.split("/")[2].replace(/^www\./, ""));+}++// A board on an older version sends no hidden_properties.+function isPropertyHidden(property) {+ return (state.board?.hidden_properties || []).includes(property);+}+function isHumanOnly() {- return localStorageGet("kanzo.humanOnly") === "1";+ return localStorageGet("kanzo.humanOnly") === "1" && !isPropertyHidden("human");}function setHumanOnly(humanOnly) {@@ -663,7 +679,7 @@ function card(t, showProject) {t.human ? el("span", { class: "human-mark", title: "Human task: agents skip it" }, icon("human")) : null,el("span", { class: "num", title: `Copy ${key(t)}`, onclick: (e) => { e.stopPropagation(); copyKey(key(t)); } },showProject ? el("span", { class: "dot", style: `background:${projectColor(t.project)}` }) : null, `#${t.id}`)),- ...summary(t));+ ...summary(t, urlChip(t)));node.addEventListener("dragstart", (e) => {state.dragging = t.id;e.dataTransfer.effectAllowed = "move";@@ -832,7 +848,7 @@ async function refreshTask() {$("#p-key").title = `Copy ${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], [$("#p-tags"), task.tags.join(", ")]]) {+ for (const [field, value] of [[$("#p-title"), task.title], [$("#p-desc"), task.description], [$("#p-tags"), task.tags.join(", ")], [$("#p-url"), task.url || ""]]) {if (document.activeElement !== field) { field.value = value; fit(field); }}showDesc();@@ -1035,6 +1051,17 @@ $("#p-tags").addEventListener("blur", (e) => {else e.target.value = panelTask.tags.join(", ");});+$("#p-url").addEventListener("keydown", (e) => {+ if (e.key === "Enter") { e.preventDefault(); e.target.blur(); }+ else if (e.key === "Escape") cancelField(e, panelTask ? panelTask.url || "" : "");+});+$("#p-url").addEventListener("blur", (e) => {+ if (!panelTask) return;+ const url = e.target.value.trim();+ if (url !== (panelTask.url || "")) patchTask({ url });+ else e.target.value = url;+});+$("#p-comment-form").addEventListener("submit", async (e) => {e.preventDefault();const body = $("#p-comment").value.trim();@@ -1383,6 +1410,7 @@ $("#settings").addEventListener("click", toggleSettingsMenu);function openSettings(section = "board") {closeMenu();$("#settings-backlog").checked = state.board?.statuses.includes("backlog") ?? false;+ document.querySelectorAll("[data-property]").forEach((box) => { box.checked = !isPropertyHidden(box.dataset.property); });$("#sync-url").value = syncRemote || "";$("#sync-create").hidden = !!syncRemote;$("#sync-error").hidden = true;@@ -1412,13 +1440,21 @@ for (const [dialog, close] of [[$("#project-dialog"), hideNewProject], [$("#seardialog.addEventListener("mousedown", (e) => { if (e.target === dialog) close(); });dialog.addEventListener("keydown", (e) => { if (e.key === "Escape") { e.stopPropagation(); close(); } });}-$("#settings-backlog").addEventListener("change", async (e) => {- const box = e.target;+async function saveSetting(box, fields) {try {- await api("PATCH", "/settings", { backlog: box.checked });+ await api("PATCH", "/settings", fields);loadBoard();} catch (err) { box.checked = !box.checked; toast(err.message); }-});+}+$("#settings-backlog").addEventListener("change", (e) => saveSetting(e.target, { backlog: e.target.checked }));+$('.settings-pane[data-section="board"]').append(...["Description", "Tags", "URL", "Human", "Created", "Updated", "Comments", "Images"].map((name) => {+ const property = name.toLowerCase();+ return el("label", { class: "setting" }, el("span", { class: "text" }, name),+ el("span", { class: "switch" },+ el("input", { type: "checkbox", "data-property": property, "aria-label": name,+ onchange: (e) => saveSetting(e.target, { property, visible: e.target.checked }) }),+ el("span")));+}));$("#settings-update").addEventListener("click", checkForUpdates);async function checkUpdate() {diff --git a/src/export.rs b/src/export.rsindex 045008d..322e9c3 100644--- a/src/export.rs+++ b/src/export.rs@@ -34,6 +34,7 @@ struct TaskOut {title: String,description: String,tags: Vec<String>,+ url: String,human: bool,images: Vec<String>,status: String,@@ -50,6 +51,7 @@ impl TaskOut {title: task.title,description: task.description,tags: task.tags,+ url: task.url,human: task.human,images,status: task.status,@@ -138,6 +140,9 @@ fn markdown(board: &Board) -> String {if !t.tags.is_empty() {let _ = writeln!(md, "Tags: {}.", t.tags.join(", "));}+ if !t.url.is_empty() {+ let _ = writeln!(md, "URL: <{}>", t.url);+ }if !t.images.is_empty() {let _ = writeln!(md, "Images: {}.", t.images.join(", "));}diff --git a/src/index.html b/src/index.htmlindex ab7ea0c..80a9347 100644--- a/src/index.html+++ b/src/index.html@@ -233,6 +233,9 @@ header .repo-link .icon svg { width: 14px; height: 14px; }background: var(--hover); border-radius: 99px; padding: 1px 9px 1px 8px;}.tag .dot { width: 6px; height: 6px; }+.tag.url { gap: 4px; color: var(--text); text-decoration: none; }+.tag.url:hover { background: var(--active); }+.tag.url .icon svg { width: 12px; height: 12px; }.drop-line { height: 2px; background: var(--text); border-radius: 2px; margin: -4px 4px; }.empty {margin: auto; text-align: center; color: var(--muted); max-width: 380px; padding: 40px 20px;@@ -270,6 +273,14 @@ header .repo-link .icon svg { width: 14px; height: 14px; }.props { display: grid; grid-template-columns: 96px 1fr; gap: 8px 12px; align-items: center; color: var(--muted); }.props select { width: auto; padding: 4px 30px 4px 12px; border-radius: 99px; text-transform: capitalize; }.props span { color: var(--text); }+.props > [data-prop] { display: contents; }+[data-hide~="description"] .desc, [data-hide~="description"] [data-prop="description"],+[data-hide~="tags"] [data-prop="tags"], [data-hide~="url"] [data-prop="url"],+[data-hide~="human"] .human-mark, [data-hide~="human"] [data-prop="human"],+[data-hide~="created"] [data-prop="created"],+[data-hide~="updated"] [data-prop="updated"],+[data-hide~="comments"] .result .comments, [data-hide~="comments"] [data-prop="comments"],+[data-hide~="images"] .panel .thumbs { display: none; }.section h3 {font-size: 13px; color: var(--muted); margin: 0 0 8px; font-weight: 600;display: flex; align-items: center; gap: 8px;@@ -363,6 +374,7 @@ header .repo-link .icon svg { width: 14px; height: 14px; }#settings-nav .active { background: var(--active); }.settings-pane { display: flex; flex-direction: column; gap: 12px; padding: 18px 22px; overflow-y: auto; }.settings-pane h3 { margin: 0; font-size: 15px; font-weight: 600; }+.settings-pane .setting + h3 { margin-top: 12px; }.settings-pane p { margin: 0; color: var(--muted); line-height: 1.45; }.settings-pane .error { color: var(--danger); white-space: pre-line; font-size: 13px; }.settings-pane .row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }@@ -480,18 +492,19 @@ label.setting { cursor: pointer; }<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>- Human <span class="human-field"><label class="switch"><input type="checkbox" id="p-human" aria-label="Human task"><span></span></label><span class="hint">Agents skip it</span></span>- Created <span id="p-created"></span>- Updated <span id="p-updated"></span>+ <div data-prop="tags">Tags <span><input class="inline" id="p-tags" placeholder="Add tags, like bug, ui" autocomplete="off" spellcheck="false"></span></div>+ <div data-prop="url">URL <span><input class="inline" id="p-url" type="url" placeholder="Add a link, like a pull request" autocomplete="off" spellcheck="false"></span></div>+ <div data-prop="human">Human <span class="human-field"><label class="switch"><input type="checkbox" id="p-human" aria-label="Human task"><span></span></label><span class="hint">Agents skip it</span></span></div>+ <div data-prop="created">Created <span id="p-created"></span></div>+ <div data-prop="updated">Updated <span id="p-updated"></span></div></div>- <div class="section">+ <div class="section" data-prop="description"><h3>Description</h3><textarea class="inline desc-input" id="p-desc" rows="1" placeholder="Add a description (Markdown)"></textarea><div class="inline md desc-view" id="p-desc-view" tabindex="0" role="button" aria-label="Edit description" hidden></div><div class="thumbs" id="p-images"></div></div>- <div class="section">+ <div class="section" data-prop="comments"><h3>Comments <span class="count" id="p-comment-count"></span></h3><div id="p-comments"></div><form class="composer" id="p-comment-form">@@ -521,6 +534,8 @@ label.setting { cursor: pointer; }<span class="text">Backlog column<span>A column before todo, for tasks agents leave alone</span></span><span class="switch"><input type="checkbox" id="settings-backlog" aria-label="Backlog column"><span></span></span></label>+ <h3>Task properties</h3>+ <p>Turn one off to hide it on the board and leave it out of what agents get. Nothing is deleted.</p></section><form class="settings-pane" data-section="sync" id="sync-form"><h3>Sync</h3>diff --git a/src/mcp.rs b/src/mcp.rsindex 613c8c9..4fffcc2 100644--- a/src/mcp.rs+++ b/src/mcp.rs@@ -37,7 +37,7 @@ macro_rules! instructions {" machine, for all their projects. Tasks look like api#12. ",$project," Keep it current unasked: doing when you start a task, comments on what you did, review when you \- finish or get stuck. Leave done and human tasks to the user."+ finish or get stuck, url for a PR you opened. Leave done and human tasks to the user.")};}@@ -224,6 +224,8 @@ struct UpdateTaskArgs {tags: Option<String>,/// For the user, not for agents.human: Option<bool>,+ /// A link; "" clears.+ url: Option<String>,}#[derive(Deserialize, JsonSchema)]@@ -390,13 +392,14 @@ impl Kanzo {let (tasks, hidden) =store.list_tasks_keeping_done(project.as_ref().map(|p| p.id), only, Some(keep))?;let done = store::DONE;+ let properties = store.hidden_properties()?;let mut out = String::new();let mut people = 0;for t in &tasks {if t.human {people += 1;} else {- task_line(&mut out, t);+ task_line(&mut out, t, &properties);out.push('\n');}}@@ -404,7 +407,7 @@ impl Kanzo {let scope = project.as_ref().map_or("any project", |p| p.slug.as_str());let _ = writeln!(out, "No tasks in {scope}.");}- if people > 0 {+ if people > 0 && shown(&properties, "human") {let _ = writeln!(out,"({people} human {} not shown: for the user, not for agents)",@@ -472,6 +475,7 @@ impl Kanzo {tags: args.tags,project_id: None,human: args.human,+ url: args.url,},)?;let moved = if before.status != after.status {@@ -526,8 +530,10 @@ impl Kanzo {Ok(self.run(move |ctx, store| {let task = args.id.find(store)?;+ let properties = store.hidden_properties()?;ctx.home.deleting_images(store, store::ImagesOf::Task(task.id), || store.delete_task(task.id))?;- let comments = match task.comments {+ let count = if shown(&properties, "comments") { task.comments } else { 0 };+ let comments = match count {0 => String::new(),1 => " and its comment".into(),n => format!(" and its {n} comments"),@@ -571,10 +577,16 @@ impl ServerHandler for Kanzo {}}-fn task_line(out: &mut String, t: &Task) {+fn shown(hidden: &[String], property: &str) -> bool {+ !hidden.iter().any(|p| p == property)+}++fn task_line(out: &mut String, t: &Task, hidden: &[String]) {let _ = write!(out, "{} [{}] {}", t.key(), t.status, t.title);- write_tags(out, t);- match t.comments {+ if shown(hidden, "tags") {+ write_tags(out, t);+ }+ match if shown(hidden, "comments") { t.comments } else { 0 } {0 => {}1 => out.push_str(" (1 comment)"),n => {@@ -590,25 +602,33 @@ fn write_tags(out: &mut String, t: &Task) {}fn task_detail(ctx: &Ctx, store: &Store, t: &Task) -> store::Result<String> {- let comments = store.list_comments(t.id)?;- let images = store.list_images(t.id)?;+ let hidden = store.hidden_properties()?;+ let comments = if shown(&hidden, "comments") { store.list_comments(t.id)? } else { Vec::new() };+ let images = if shown(&hidden, "images") { store.list_images(t.id)? } else { Vec::new() };let dir = &ctx.images;let paths = |comment: Option<i64>| -> Vec<String> {images.iter().filter(|i| i.comment_id == comment).map(|i| dir.join(&i.file).display().to_string()).collect()};let (created, updated) = (short_time(&t.created_at), short_time(&t.updated_at));let mut out = format!("{} {}", t.key(), t.title);- write_tags(&mut out, t);+ if shown(&hidden, "tags") {+ write_tags(&mut out, t);+ }let _ = write!(out, "\nstatus: {}", t.status);- if t.human {+ if t.human && shown(&hidden, "human") {out.push_str(", human: for the user, not for agents");}- let _ = write!(out, ", created {created}");- if updated != created {+ if shown(&hidden, "created") {+ let _ = write!(out, ", created {created}");+ }+ if updated != created && shown(&hidden, "updated") {let _ = write!(out, ", updated {updated}");}+ if !t.url.is_empty() && shown(&hidden, "url") {+ let _ = write!(out, "\nurl: {}", t.url);+ }out.push('\n');- if !t.description.is_empty() {+ if !t.description.is_empty() && shown(&hidden, "description") {let _ = writeln!(out, "\n{}", t.description);}let own = paths(None);diff --git a/src/store.rs b/src/store.rsindex f6bcae5..8cf8d75 100644--- a/src/store.rs+++ b/src/store.rs@@ -41,6 +41,7 @@ const MIGRATIONS: &[&str] = &[CREATE TRIGGER images_insert AFTER INSERT ON images BEGIN UPDATE meta SET value = value + 1 WHERE key = 'changes'; END;CREATE TRIGGER images_delete AFTER DELETE ON images BEGIN UPDATE meta SET value = value + 1 WHERE key = 'changes'; END;","ALTER TABLE tasks ADD COLUMN human INTEGER NOT NULL DEFAULT 0;",+ "ALTER TABLE tasks ADD COLUMN url TEXT NOT NULL DEFAULT '';",];const PROJECT_COLORS: &[&str] = &["gray", "red", "orange", "yellow", "green", "teal", "blue", "purple", "pink"];@@ -100,6 +101,8 @@ pub struct Task {pub title: String,pub description: String,pub tags: Vec<String>,+ /// A link to anything, like the task's pull request; empty when there is none.+ pub url: String,pub human: bool,pub status: String,pub position: f64,@@ -138,6 +141,7 @@ pub struct TaskPatch {pub status: Option<String>,pub project_id: Option<i64>,pub tags: Option<String>,+ pub url: Option<String>,pub human: Option<bool>,}@@ -147,6 +151,9 @@ pub const DONE: &str = STATUSES[3];pub const BACKLOG: &str = "backlog";+/// What a task shows besides its id, title and status; each can be turned off in Settings.+const PROPERTIES: [&str; 8] = ["description", "tags", "url", "human", "created", "updated", "comments", "images"];+pub struct Store {conn: Connection,statuses: Vec<String>,@@ -193,6 +200,35 @@ impl Store {})}+ /// The properties turned off in Settings: off the board, and out of what agents get.+ pub fn hidden_properties(&self) -> Result<Vec<String>> {+ let hidden: Option<String> = self+ .conn+ .query_row("SELECT value FROM meta WHERE key = 'hidden_properties'", [], |r| r.get(0))+ .optional()?;+ Ok(hidden.unwrap_or_default().split(',').filter(|p| !p.is_empty()).map(String::from).collect())+ }++ pub fn set_property(&self, property: &str, visible: bool) -> Result<()> {+ if !PROPERTIES.contains(&property) {+ return Err(Error::Invalid(format!("unknown property {property:?}")));+ }+ self.write(|c| {+ let mut hidden = self.hidden_properties()?;+ hidden.retain(|p| p != property);+ if !visible {+ hidden.push(property.to_string());+ }+ c.execute(+ "INSERT INTO meta (key, value) VALUES ('hidden_properties', ?1) ON CONFLICT(key) DO UPDATE SET value = excluded.value",+ [hidden.join(",")],+ )?;+ // Other open boards redraw their tasks.+ c.execute("UPDATE meta SET value = value + 1 WHERE key = 'changes'", [])?;+ Ok(())+ })+ }+/// Immediate, so concurrent writers queue up on the busy timeout instead of failing halfway.fn write<T>(&self, f: impl FnOnce(&Connection) -> Result<T>) -> Result<T> {self.conn.execute_batch("BEGIN IMMEDIATE")?;@@ -418,7 +454,8 @@ impl Store {}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.tags, t.human+ t.created_at, t.updated_at, (SELECT count(*) FROM comments c WHERE c.task_id = t.id), t.tags, t.human,+ t.urlFROM tasks t JOIN projects p ON p.id = t.project_id";fn task_row(r: &Row) -> rusqlite::Result<Task> {@@ -428,6 +465,7 @@ impl Store {title: r.get(2)?,description: r.get(3)?,tags: r.get::<_, String>(9)?.split(',').filter(|t| !t.is_empty()).map(String::from).collect(),+ url: r.get(11)?,human: r.get(10)?,status: r.get(4)?,position: r.get(5)?,@@ -567,6 +605,7 @@ impl Store {pub fn update_task(&self, id: i64, patch: TaskPatch) -> Result<Task> {let title = patch.title.as_deref().map(clean_title).transpose()?;+ let url = patch.url.as_deref().map(clean_url).transpose()?;if let Some(s) = &patch.status {self.check_status(s)?;}@@ -578,11 +617,20 @@ impl Store {&format!("UPDATE tasks SET title = coalesce(?1, title), project_id = coalesce(?2, project_id),human = coalesce(?3, human), tags = coalesce(?4, tags),- description = coalesce(?5, description), updated_at = {NOW}+ description = coalesce(?5, description), url = coalesce(?7, url), updated_at = {NOW}WHERE id = ?6 AND (coalesce(?1, title), coalesce(?2, project_id), coalesce(?3, human),- coalesce(?4, tags), coalesce(?5, description)) <> (title, project_id, human, tags, description)"+ coalesce(?4, tags), coalesce(?5, description), coalesce(?7, url))+ <> (title, project_id, human, tags, description, url)"),- params![title, patch.project_id, patch.human, tags, patch.description.as_deref().map(str::trim), id],+ params![+ title,+ patch.project_id,+ patch.human,+ tags,+ patch.description.as_deref().map(str::trim),+ id,+ url+ ],)?;if let Some(s) = &patch.status&& *s != current.status@@ -847,6 +895,22 @@ fn clean_tags(input: &str) -> Vec<String> {tags}+/// Any site will do, but only http and https: the board makes it a link people click.+fn clean_url(input: &str) -> Result<String> {+ let url = input.trim();+ if url.is_empty() {+ return Ok(String::new());+ }+ let host = url+ .split_once("://")+ .filter(|(scheme, _)| scheme.eq_ignore_ascii_case("http") || scheme.eq_ignore_ascii_case("https"))+ .and_then(|(_, rest)| rest.split(['/', '?', '#']).next());+ if host.is_none_or(str::is_empty) || url.chars().any(char::is_whitespace) {+ return Err(Error::Invalid(format!("URL {url:?} should start with http:// or https://")));+ }+ Ok(url.to_string())+}+fn clean_repo(repo: &str) -> Result<String> {repo_from_url(repo).ok_or_else(|| Error::Invalid(format!("repo {:?} should look like owner/repo", repo.trim())))}@@ -1217,6 +1281,28 @@ mod tests {s.set_backlog(false).unwrap();}+ #[test]+ fn hidden_properties_keep_their_data() {+ let (_dir, s) = store();+ assert!(s.hidden_properties().unwrap().is_empty());+ let api = s.create_project("api", "", None).unwrap();+ let t = s.create_task(api.id, "x", "Why").unwrap();+ let before = s.changes().unwrap();++ s.set_property("description", false).unwrap();+ s.set_property("tags", false).unwrap();+ s.set_property("tags", false).unwrap();+ assert_eq!(s.hidden_properties().unwrap(), ["description", "tags"]);+ assert!(s.changes().unwrap() > before, "other open boards redraw");+ assert_eq!(s.get_task(t.id).unwrap().description, "Why");++ s.set_property("description", true).unwrap();+ assert_eq!(s.hidden_properties().unwrap(), ["tags"]);+ for always in ["title", "status", "nope"] {+ assert!(s.set_property(always, false).is_err(), "{always}");+ }+ }+#[test]fn change_counter_moves_on_every_write() {let (_dir, s) = store();@@ -1230,6 +1316,39 @@ mod tests {assert!(c0 < c1 && c1 < c2 && c2 < c3);}+ #[test]+ fn a_task_links_to_one_url_on_any_site() {+ let (_dir, s) = store();+ let api = s.create_project("api", "", None).unwrap();+ let t = s.create_task(api.id, "Fix login", "").unwrap();+ assert_eq!(t.url, "");+ let set = |url: &str| s.update_task(t.id, TaskPatch { url: Some(url.into()), ..Default::default() });+ for url in [+ "https://github.com/Me/Api/pull/12",+ "https://gitlab.example.com/a/b/-/merge_requests/3?x=1#y",+ "http://intranet",+ ] {+ assert_eq!(set(&format!(" {url} ")).unwrap().url, url);+ }+ for bad in [+ "#12",+ "owner/repo#12",+ "github.com/a/b",+ "javascript:alert(1)",+ "javascript://x",+ "https://",+ "https://a b",+ ] {+ assert!(set(bad).unwrap_err().to_string().contains("should start with"), "{bad}");+ }+ assert_eq!(s.get_task(t.id).unwrap().url, "http://intranet", "a bad URL changes nothing");+ assert_eq!(+ s.update_task(t.id, TaskPatch { title: Some("Fix".into()), ..Default::default() }).unwrap().url,+ "http://intranet"+ );+ assert_eq!(set("").unwrap().url, "");+ }+#[test]fn task_keys() {assert_eq!(parse_task_key("api#12").unwrap(), (Some("api".into()), 12));diff --git a/src/web.rs b/src/web.rsindex 2d0b7ef..923a4fd 100644--- a/src/web.rs+++ b/src/web.rs@@ -400,6 +400,7 @@ struct BoardQuery {struct Board {changes: String,done_hidden: usize,+ hidden_properties: Vec<String>,projects: Vec<store::Project>,statuses: Vec<String>,tasks: Vec<store::Task>,@@ -421,6 +422,7 @@ async fn board(State(home): Shared, Query(q): Query<BoardQuery>) -> Response {Ok(Board {changes: change_token(h, s)?,done_hidden,+ hidden_properties: s.hidden_properties()?,projects: s.list_projects()?,statuses: s.statuses().to_vec(),tasks,@@ -510,12 +512,18 @@ async fn create_task(State(home): Shared, Json(t): Json<NewTask>) -> Response {}#[derive(Deserialize)]-struct Settings {- backlog: bool,+#[serde(untagged)]+enum Settings {+ Backlog { backlog: bool },+ Property { property: String, visible: bool },}async fn update_settings(State(home): Shared, Json(r): Json<Settings>) -> Response {- with_store(home, move |_, s| s.set_backlog(r.backlog)).await+ with_store(home, move |_, s| match r {+ Settings::Backlog { backlog } => s.set_backlog(backlog),+ Settings::Property { property, visible } => s.set_property(&property, visible),+ })+ .await}#[derive(Serialize)]@@ -540,6 +548,7 @@ struct Patch {project: Option<String>,tags: Option<String>,human: Option<bool>,+ url: Option<String>,}async fn update_task(State(home): Shared, Path(id): Path<i64>, Json(p): Json<Patch>) -> Response {@@ -554,6 +563,7 @@ async fn update_task(State(home): Shared, Path(id): Path<i64>, Json(p): Json<Patproject_id,tags: p.tags,human: p.human,+ url: p.url,},)})