diff options
| author | Ben Sima <ben@bensima.com> | 2025-12-01 07:40:49 -0500 |
|---|---|---|
| committer | Ben Sima <ben@bensima.com> | 2025-12-01 07:40:49 -0500 |
| commit | 4919cf825d4fdbcecc1f69fcf2a32176dfdde5ac (patch) | |
| tree | 0853eef48784ffb840589ddfdd305de7507f11cd /Omni/Task | |
| parent | e3f20289bdf3014b418367931fbd9cf96239061a (diff) | |
Add author field to task comments (Human vs Junior)
Comments now track whether they were made by a Human or by Junior
(the agent). The CommentAuthor type is stored in the database and
displayed in the web UI with styled badges.
Task-Id: t-201
Diffstat (limited to 'Omni/Task')
| -rw-r--r-- | Omni/Task/Core.hs | 27 |
1 files changed, 23 insertions, 4 deletions
diff --git a/Omni/Task/Core.hs b/Omni/Task/Core.hs index 6a6d1b8..f54cf81 100644 --- a/Omni/Task/Core.hs +++ b/Omni/Task/Core.hs @@ -140,9 +140,14 @@ data Fact = Fact } deriving (Show, Eq, Generic) +-- Comment author +data CommentAuthor = Human | Junior + deriving (Show, Eq, Read, Generic) + -- Comment for task notes/context data Comment = Comment { commentText :: Text, + commentAuthor :: CommentAuthor, commentCreatedAt :: UTCTime } deriving (Show, Eq, Generic) @@ -195,6 +200,10 @@ instance ToJSON Fact instance FromJSON Fact +instance ToJSON CommentAuthor + +instance FromJSON CommentAuthor + instance ToJSON Comment instance FromJSON Comment @@ -257,6 +266,16 @@ instance SQL.FromField ActivityStage where instance SQL.ToField ActivityStage where toField x = SQL.toField (show x :: String) +instance SQL.FromField CommentAuthor where + fromField f = do + t <- SQL.fromField f :: SQLOk.Ok String + case readMaybe t of + Just x -> pure x + Nothing -> SQL.returnError SQL.ConversionFailed f "Invalid CommentAuthor" + +instance SQL.ToField CommentAuthor where + toField x = SQL.toField (show x :: String) + -- Store dependencies as JSON text instance SQL.FromField [Dependency] where fromField f = do @@ -752,15 +771,15 @@ deleteTask tid = SQL.execute conn "DELETE FROM tasks WHERE id = ?" (SQL.Only tid) -- Add a comment to a task -addComment :: Text -> Text -> IO Task -addComment tid commentText = +addComment :: Text -> Text -> CommentAuthor -> IO Task +addComment tid commentText author = withTaskLock <| do tasks <- loadTasks case findTask tid tasks of Nothing -> panic "Task not found" Just task -> do now <- getCurrentTime - let newComment = Comment {commentText = commentText, commentCreatedAt = now} + let newComment = Comment {commentText = commentText, commentAuthor = author, commentCreatedAt = now} updatedTask = task {taskComments = taskComments task ++ [newComment], taskUpdatedAt = now} saveTask updatedTask pure updatedTask @@ -1068,7 +1087,7 @@ showTaskDetailed t = do putText <| " - " <> depId dep <> " [" <> T.pack (show (depType dep)) <> "]" printComment c = - putText <| " [" <> T.pack (show (commentCreatedAt c)) <> "] " <> commentText c + putText <| " [" <> T.pack (show (commentCreatedAt c)) <> "] [" <> T.pack (show (commentAuthor c)) <> "] " <> commentText c red, green, yellow, blue, magenta, cyan, gray, bold :: Text -> Text red t = "\ESC[31m" <> t <> "\ESC[0m" |
