From 14eda5bce294e0f01fb73a95edafa9afeec530e3 Mon Sep 17 00:00:00 2001 From: Noah Pederson Date: Sun, 31 May 2026 19:27:42 -0500 Subject: [PATCH] Add tsk open command --- readme | 3 +++ src/commands.rs | 18 ++++++++++++++++++ src/lib.rs | 6 ++++++ src/workspace.rs | 43 +++++++++++++++++++++++++++++++++++++++++++ tests/multi_user.rs | 27 +++++++++++++++++++++++++++ 5 files changed, 97 insertions(+) diff --git a/readme b/readme index 814fb54..3bb208f 100644 --- a/readme +++ b/readme @@ -73,6 +73,9 @@ scoped to the namespace and may be used to as a stable reference within that namespace. The contents of the stack may be printed using the `tsk list` command. +Open tasks across the active namespace may be printed using `tsk open`; it +shows each task id, the queue index or indexes containing it (comma-separated), +or `none` when the open task is not currently queued. Tasks are marked as "completed" and removed from the index with the `tsk drop` command. They will remain in the .tsk/archive folder, but are excluded from diff --git a/src/commands.rs b/src/commands.rs index d2e317c..e7fa404 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -182,6 +182,24 @@ pub(crate) fn command_list(dir: PathBuf, all: bool, count: usize, ids_only: bool Ok(()) } +pub(crate) fn command_open(dir: PathBuf) -> Result<()> { + let ws = Workspace::from_path(dir)?; + let tasks = ws.open_tasks()?; + if tasks.is_empty() { + println!("*No open tasks*"); + return Ok(()); + } + for task in tasks { + let queues = if task.queues.is_empty() { + "none".to_string() + } else { + task.queues.join(",") + }; + println!("{}\t{}\t{}", task.id, queues, task.title); + } + Ok(()) +} + pub(crate) fn command_find(dir: PathBuf, multi: bool, all: bool, body: bool) -> Result<()> { let ws = Workspace::from_path(dir.clone())?; let entries = if all { diff --git a/src/lib.rs b/src/lib.rs index db27536..4af0884 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -92,6 +92,11 @@ enum Commands { #[arg(short = 'i', default_value_t = false)] ids_only: bool, }, + /// Print open tasks in the active namespace, with queue membership. + /// + /// Queue membership is printed as a comma-separated list, or `none` + /// when the open task is not currently in any queue index. + Open, /// Fuzzy-find tasks and print the selected task id(s). Find { /// Allow selecting multiple tasks. @@ -518,6 +523,7 @@ fn dispatch(cli: Cli) -> Result<()> { count, ids_only, } => commands::command_list(dir, all, count, ids_only), + Commands::Open => commands::command_open(dir), Commands::Find { multi, all, body } => commands::command_find(dir, multi, all, body), Commands::Show { task_id, diff --git a/src/workspace.rs b/src/workspace.rs index 5ac874e..451c528 100644 --- a/src/workspace.rs +++ b/src/workspace.rs @@ -126,6 +126,13 @@ pub struct StackEntry { pub title: String, } +/// One row of the open-task listing. +pub struct OpenTaskEntry { + pub id: Id, + pub title: String, + pub queues: Vec, +} + /// User-facing task: human id (in active namespace) + content + properties. /// Each property holds zero or more text values. #[derive(Debug)] @@ -866,6 +873,42 @@ impl Workspace { Ok(out) } + /// Every open task bound in the active namespace, annotated with queue + /// index membership. Queue membership is informational here; lifecycle + /// comes from the task's `status` property. + pub fn open_tasks(&self) -> Result> { + let repo = self.repo()?; + let mut queues_by_stable: BTreeMap> = BTreeMap::new(); + for queue_name in queue::list_names(&repo)? { + for stable in queue::read(&repo, &queue_name)?.index { + queues_by_stable + .entry(stable) + .or_default() + .push(queue_name.clone()); + } + } + + let mut out = Vec::new(); + for (human, stable) in namespace::read(&repo, &self.namespace()?)?.mapping { + let Some(task) = object::read(&repo, &stable)? else { + continue; + }; + let is_open = task + .properties + .get(STATUS_KEY) + .is_some_and(|values| values.iter().any(|value| value == STATUS_OPEN)); + if !is_open { + continue; + } + out.push(OpenTaskEntry { + id: Id(human), + title: task.title().to_string(), + queues: queues_by_stable.remove(&stable).unwrap_or_default(), + }); + } + Ok(out) + } + /// Unique property keys on tasks bound in `name`, sorted alphabetically. pub fn namespace_property_keys(&self, name: &str) -> Result> { let repo = self.repo()?; diff --git a/tests/multi_user.rs b/tests/multi_user.rs index a47fcf6..5df5bbb 100644 --- a/tests/multi_user.rs +++ b/tests/multi_user.rs @@ -168,6 +168,33 @@ fn share_and_pull_between_clones() { ); } +#[test] +fn open_lists_open_tasks_with_queue_membership() { + let dir = tempfile::tempdir().unwrap(); + init_repo_with_commit(dir.path()); + + tsk_ok(dir.path(), &["push", "queued open"]); + tsk_ok(dir.path(), &["queue", "create", "review"]); + tsk_ok(dir.path(), &["push", "unqueued open"]); + tsk_ok(dir.path(), &["assign", "review", "-T", "tsk-2", "-R", ""]); + tsk_ok(dir.path(), &["push", "closed task"]); + tsk_ok(dir.path(), &["drop", "-T", "tsk-3"]); + + let open = tsk_ok(dir.path(), &["open"]); + assert!( + open.contains("tsk-1\ttsk\tqueued open"), + "queued open task should report queue membership: {open:?}" + ); + assert!( + open.contains("tsk-2\tnone\tunqueued open"), + "open task outside queue indexes should report none: {open:?}" + ); + assert!( + !open.contains("closed task"), + "done tasks should be excluded from tsk open: {open:?}" + ); +} + #[test] fn assign_to_other_queue_visible_after_push_pull() { let (_dir, alice, bob) = setup_two_clones(); -- knotmirror 0.0.1