From bd7724068938daa44dc74c28ab0aa5c45477bbfd Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Thu, 18 Dec 2025 13:39:40 -0500 Subject: Omni/Agent/Subagent/Coder: decouple from jr task system Remove task_id requirement and all jr task CLI calls. The Coder subagent now only requires namespace and task description - no external task tracking needed. Changes: - Remove coderTaskId from CoderConfig - Remove jr task show/update/comment calls - Commit message uses namespace prefix instead of task ID - Recovery phase just reverts git, no task comment - Subagent.hs only validates namespace for Coder role --- Omni/Agent/Telegram.hs | 36 ++++++++++++++++++++++++++++++------ 1 file changed, 30 insertions(+), 6 deletions(-) (limited to 'Omni/Agent/Telegram.hs') diff --git a/Omni/Agent/Telegram.hs b/Omni/Agent/Telegram.hs index 23a760a..9e6eca0 100644 --- a/Omni/Agent/Telegram.hs +++ b/Omni/Agent/Telegram.hs @@ -240,6 +240,8 @@ getRawUpdates cfg offset = do <> show (Types.tgPollingTimeout cfg) <> "&offset=" <> show offset + <> "&allowed_updates=" + <> "%5B%22message%22%2C%22callback_query%22%5D" result <- try <| do req0 <- HTTP.parseRequest url @@ -539,8 +541,13 @@ runTelegramBot tgConfig provider = do offset <- readTVarIO offsetVar rawUpdates <- getRawUpdates tgConfig offset forM_ rawUpdates <| \rawUpdate -> do + let hasCallbackField = case rawUpdate of + Aeson.Object obj -> isJust (KeyMap.lookup "callback_query" obj) + _ -> False + when hasCallbackField <| putText <| "Raw callback update received: " <> Text.take 300 (tshow rawUpdate) case Types.parseCallbackQuery rawUpdate of Just cq -> do + putText <| "Parsed callback query: " <> Types.cqData cq let updateId = getUpdateId rawUpdate forM_ updateId <| \uid -> atomically (writeTVar offsetVar (uid + 1)) handleCallbackQuery tgConfig cq @@ -555,7 +562,12 @@ runTelegramBot tgConfig provider = do IncomingQueue.enqueueIncoming incomingQueues IncomingQueue.defaultBatchWindowSeconds msg Nothing -> do let updateId = getUpdateId rawUpdate - putText <| "Unparsed update: " <> Text.take 200 (tshow rawUpdate) + hasCallback = case rawUpdate of + Aeson.Object obj -> isJust (KeyMap.lookup "callback_query" obj) + _ -> False + if hasCallback + then putText <| "Failed to parse callback_query: " <> Text.take 500 (tshow rawUpdate) + else putText <| "Unparsed update: " <> Text.take 200 (tshow rawUpdate) forM_ updateId <| \uid -> atomically (writeTVar offsetVar (uid + 1)) when (null rawUpdates) <| threadDelay 1000000 @@ -588,30 +600,42 @@ handleCallbackQuery tgConfig cq = do userId = Types.cqFromId cq userName = Types.cqFromFirstName cq putText <| "Callback query from " <> userName <> ": " <> callbackData + result <- try @SomeException <| handleCallbackQueryInner tgConfig cq chatId userId callbackData + case result of + Left err -> putText <| "Callback handler error: " <> tshow err + Right () -> pure () + +handleCallbackQueryInner :: Types.TelegramConfig -> Types.CallbackQuery -> Int -> Int -> Text -> IO () +handleCallbackQueryInner tgConfig cq chatId userId callbackData = do if not (Types.isUserAllowed tgConfig userId) then do answerCallbackQuery tgConfig (Types.cqId cq) (Just "Not authorized") putText <| "Unauthorized callback from user " <> tshow userId else case Text.splitOn ":" callbackData of ["subagent_approve", pendingId] -> do + putText <| "Approving subagent spawn: " <> pendingId answerCallbackQuery tgConfig (Types.cqId cq) (Just "Spawning subagent...") let keys = Subagent.SubagentApiKeys { Subagent.subagentOpenRouterKey = Types.tgOpenRouterApiKey tgConfig, Subagent.subagentKagiKey = Types.tgKagiApiKey tgConfig } - result <- Subagent.approveAndSpawnSubagent keys pendingId - case result of + spawnResult <- Subagent.approveAndSpawnSubagent keys pendingId + putText <| "Spawn result: " <> tshow spawnResult + case spawnResult of Left err -> do - sendMessage tgConfig chatId ("❌ Failed to spawn subagent: " <> err) + putText <| "Spawn failed: " <> err + sendMessage tgConfig chatId ("Failed to spawn subagent: " <> err) Right subagentId -> do - sendMessage tgConfig chatId ("🚀 Subagent **" <> subagentId <> "** spawned! Use `check_subagent` to monitor progress.") + putText <| "Spawn succeeded, subagent ID: " <> subagentId + sendMessage tgConfig chatId ("Subagent " <> subagentId <> " spawned! Use check_subagent to monitor progress.") ["subagent_reject", pendingId] -> do + putText <| "Rejecting subagent spawn: " <> pendingId rejected <- Subagent.rejectPendingSpawn pendingId if rejected then do answerCallbackQuery tgConfig (Types.cqId cq) (Just "Spawn cancelled") - sendMessage tgConfig chatId "❌ Subagent spawn cancelled." + sendMessage tgConfig chatId "Subagent spawn cancelled." else answerCallbackQuery tgConfig (Types.cqId cq) (Just "Already expired") _ -> do answerCallbackQuery tgConfig (Types.cqId cq) (Just "Unknown action") -- cgit v1.2.3