commit b4084e0cd68d75d6b445d4dfb04384a936e3ab9b
Author: Ben Sima <ben@bensima.com>
Date: Tue Dec 30 19:40:53 2025
Omni/Agent/Telegram/Orchestrator: Parse work on command in sentence
Allow 'work on t-XXX' pattern to be found anywhere in the message,
not just as the entire message.
Task-Id: t-294
diff --git a/Omni/Agent/Telegram/Orchestrator.hs b/Omni/Agent/Telegram/Orchestrator.hs
index f5f87484..d391309e 100644
--- a/Omni/Agent/Telegram/Orchestrator.hs
+++ b/Omni/Agent/Telegram/Orchestrator.hs
@@ -60,7 +60,11 @@ test =
Test.unit "parseWorkOnCommand rejects invalid input" <| do
parseWorkOnCommand "hello world" Test.@=? Nothing,
Test.unit "parseWorkOnCommand rejects missing task id" <| do
- parseWorkOnCommand "work on" Test.@=? Nothing
+ parseWorkOnCommand "work on" Test.@=? Nothing,
+ Test.unit "parseWorkOnCommand finds pattern in sentence" <| do
+ parseWorkOnCommand "Hey can you work on t-291 please" Test.@=? Just "t-291",
+ Test.unit "parseWorkOnCommand finds start pattern in sentence" <| do
+ parseWorkOnCommand "Please start t-123 now" Test.@=? Just "t-123"
]
-- | Configuration for orchestrator run
@@ -96,15 +100,18 @@ data TaskInfo = TaskInfo
deriving (Show, Eq, Generic)
-- | Parse "work on t-XXX" or "start t-XXX" style commands
--- Returns Just taskId if pattern matches, Nothing otherwise
+-- Searches for the pattern anywhere in the message
+-- Returns Just taskId if pattern found, Nothing otherwise
parseWorkOnCommand :: Text -> Maybe Text
parseWorkOnCommand input =
- let normalized = Text.strip (Text.toLower input)
+ let normalized = Text.toLower input
words' = Text.words normalized
- in case words' of
- ["work", "on", taskId] -> validateTaskId taskId
- ["start", taskId] -> validateTaskId taskId
- _ -> Nothing
+ -- Look for "work on t-XXX" pattern
+ findWorkOn [] = Nothing
+ findWorkOn ("work" : "on" : taskId : _) = validateTaskId taskId
+ findWorkOn ("start" : taskId : _) = validateTaskId taskId
+ findWorkOn (_ : rest) = findWorkOn rest
+ in findWorkOn words'
where
validateTaskId tid
| "t-" `Text.isPrefixOf` tid = Just tid