diff options
| author | Ben Sima <ben@bsima.me> | 2025-11-21 03:59:41 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bsima.me> | 2025-11-21 03:59:41 -0500 |
| commit | 16e34f875e3cea2521e5a2128c1209cc0ec6c64b (patch) | |
| tree | 453be54c3217d8fab4c7e454817a233011baa46c | |
| parent | e264175ef215a88bb127a898181825ed1e637150 (diff) | |
| parent | a8bf9a7342c040cb7bd4b839764bbfe80d97f91e (diff) | |
Merge branch 'task/t-1rcIr6X' into live
| -rw-r--r-- | Omni/Task.hs | 36 | ||||
| -rw-r--r-- | Omni/Task/Core.hs | 38 |
2 files changed, 61 insertions, 13 deletions
diff --git a/Omni/Task.hs b/Omni/Task.hs index 24e528b..19fc005 100644 --- a/Omni/Task.hs +++ b/Omni/Task.hs @@ -45,6 +45,7 @@ Usage: task update <id> <status> [--json] task deps <id> [--json] task tree [<id>] [--json] + task progress <id> [--json] task stats [--json] task export [--flush] task import -i <file> @@ -61,6 +62,7 @@ Commands: update Update task status deps Show dependency tree tree Show task tree (epics with children, or all epics if no ID given) + progress Show progress for an epic stats Show task statistics export Export and consolidate tasks to JSONL import Import tasks from JSONL file @@ -231,6 +233,13 @@ move args tree <- getTaskTree maybeId outputJson tree else showTaskTree maybeId + | args `Cli.has` Cli.command "progress" = do + tid <- getArgText args "id" + if isJsonMode args + then do + progress <- getTaskProgress tid + outputJson progress + else showTaskProgress tid | args `Cli.has` Cli.command "stats" = do if isJsonMode args then do @@ -336,20 +345,21 @@ unitTests = child1 <- createTask "Child 1" WorkTask (Just (taskId parent)) Nothing P2 [] -- Manually create a task with .3 suffix to simulate a gap (or deleted task) let child3Id = taskId parent <> ".3" - child3 = Task - { taskId = child3Id, - taskTitle = "Child 3", - taskType = WorkTask, - taskParent = Just (taskId parent), - taskNamespace = Nothing, - taskStatus = Open, - taskPriority = P2, - taskDependencies = [], - taskCreatedAt = taskCreatedAt child1, - taskUpdatedAt = taskUpdatedAt child1 - } + child3 = + Task + { taskId = child3Id, + taskTitle = "Child 3", + taskType = WorkTask, + taskParent = Just (taskId parent), + taskNamespace = Nothing, + taskStatus = Open, + taskPriority = P2, + taskDependencies = [], + taskCreatedAt = taskCreatedAt child1, + taskUpdatedAt = taskUpdatedAt child1 + } saveTask child3 - + -- Create a new child, it should get .4, not .2 child4 <- createTask "Child 4" WorkTask (Just (taskId parent)) Nothing P2 [] taskId child4 Test.@?= taskId parent <> ".4" diff --git a/Omni/Task/Core.hs b/Omni/Task/Core.hs index e4f1086..17a5ecf 100644 --- a/Omni/Task/Core.hs +++ b/Omni/Task/Core.hs @@ -57,6 +57,14 @@ data DependencyType | Related -- Soft relationship, doesn't block deriving (Show, Eq, Generic) +data TaskProgress = TaskProgress + { progressTaskId :: Text, + progressTotal :: Int, + progressCompleted :: Int, + progressPercentage :: Int + } + deriving (Show, Eq, Generic) + instance ToJSON TaskType instance FromJSON TaskType @@ -81,6 +89,10 @@ instance ToJSON Task instance FromJSON Task +instance ToJSON TaskProgress + +instance FromJSON TaskProgress + -- Get the tasks database file path (use test file if TASK_TEST_MODE is set) getTasksFilePath :: IO FilePath getTasksFilePath = do @@ -309,6 +321,32 @@ getDependencyTree tid = do deps = filter (\t -> taskId t `elem` depIds) allTasks in task : concatMap (collectDeps allTasks) deps +-- Get task progress +getTaskProgress :: Text -> IO TaskProgress +getTaskProgress tid = do + tasks <- loadTasks + -- Verify task exists (optional, but good for error handling) + case filter (\t -> taskId t == tid) tasks of + [] -> panic "Task not found" + _ -> do + let children = filter (\child -> taskParent child == Just tid) tasks + total = length children + completed = length <| filter (\child -> taskStatus child == Done) children + percentage = if total == 0 then 0 else (completed * 100) `div` total + pure + TaskProgress + { progressTaskId = tid, + progressTotal = total, + progressCompleted = completed, + progressPercentage = percentage + } + +-- Show task progress +showTaskProgress :: Text -> IO () +showTaskProgress tid = do + progress <- getTaskProgress tid + putText <| "Progress for " <> tid <> ": " <> T.pack (show (progressCompleted progress)) <> "/" <> T.pack (show (progressTotal progress)) <> " (" <> T.pack (show (progressPercentage progress)) <> "%)" + -- Show dependency tree for a task showDependencyTree :: Text -> IO () showDependencyTree tid = do |
