summaryrefslogtreecommitdiff
path: root/Omni/Agent/Worker.hs
diff options
context:
space:
mode:
authorBen Sima <ben@bensima.com>2025-11-27 10:59:38 -0500
committerBen Sima <ben@bensima.com>2025-11-27 10:59:38 -0500
commit83ff4b622be49762491dac216ab8df374b24cd74 (patch)
tree6f8d85b640716c43a309ae41e4bb61dd233bdfef /Omni/Agent/Worker.hs
parent273208a8ffd714eb9cda51d557dbc62ff3009932 (diff)
Display worker metrics on task detail page
All tests pass. Let me summarize what was implemented: - Extended `TaskActivity` type with new fields: - `activityAmpThreadUrl` - Link to amp thread - `activityStartedAt` - Work start timestamp - `activityCompletedAt` - Work completion timestamp - `activityCostCents` - API cost in cents - `activityTokensUsed` - Token usage count - Updated `SQL.FromRow` and `SQL.ToRow` instances for the new fields - Updated schema to include new columns in `task_activity` table - Added `logActivityWithMetrics` function to log activities with all met - Added `updateActivityMetrics` function to update metrics on existing a - Added `getLatestRunningActivity` helper function - Captures execution timing (start/end timestamps) - Retrieves amp thread URL from `AgentLog.getStatus` - Converts credits to cents and logs to activity record - Uses `logActivityWithMetrics` and `updateActivityMetrics` for tracking - Added `getStatus` function to retrieve current status (thread URL, cre - Added `TaskMetricsPartial` type for HTMX auto-refresh - Extended `TaskDetailPage` to include `RetryContext` - Added Execution Details section on task detail page showing: - Amp Thread URL (clickable link) - Duration (formatted as "Xm Ys") - Cost (formatted as "$X.XX") - Retry Attempt count (if applicable) - Last Activity timestamp - Added `/partials/task/:id/metrics` endpoint for HTMX auto-refresh - Auto-refresh enabled while task is InProgress (every 5s) - Added `renderExecutionDetails` helper function - Added `executionDetailsStyles` for metric rows and execution section - Added dark mode support for execution details section Task-Id: t-148.4
Diffstat (limited to 'Omni/Agent/Worker.hs')
-rw-r--r--Omni/Agent/Worker.hs15
1 files changed, 13 insertions, 2 deletions
diff --git a/Omni/Agent/Worker.hs b/Omni/Agent/Worker.hs
index 2557d70..eef31f4 100644
--- a/Omni/Agent/Worker.hs
+++ b/Omni/Agent/Worker.hs
@@ -10,6 +10,7 @@ import qualified Data.ByteString.Lazy as BSL
import qualified Data.Text as Text
import qualified Data.Text.Encoding as TE
import qualified Data.Text.IO as TIO
+import qualified Data.Time
import qualified Omni.Agent.Core as Core
import qualified Omni.Agent.Log as AgentLog
import qualified Omni.Task.Core as TaskCore
@@ -83,12 +84,22 @@ processTask worker task = do
TaskCore.updateTaskStatus tid TaskCore.InProgress []
say "[worker] Status -> InProgress"
- -- Run Amp
+ -- Run Amp with timing
say "[worker] Starting amp..."
- TaskCore.logActivity tid TaskCore.Running Nothing
+ startTime <- Data.Time.getCurrentTime
+ activityId <- TaskCore.logActivityWithMetrics tid TaskCore.Running Nothing Nothing (Just startTime) Nothing Nothing Nothing
(exitCode, output) <- runAmp repo task
+ endTime <- Data.Time.getCurrentTime
say ("[worker] Amp exited with: " <> tshow exitCode)
+ -- Capture metrics from agent log (thread URL, credits)
+ status <- AgentLog.getStatus
+ let threadUrl = ("https://ampcode.com/threads/" <>) </ AgentLog.statusThread status
+ let costCents = Just <| floor (AgentLog.statusCredits status * 100)
+
+ -- Update the activity record with metrics
+ TaskCore.updateActivityMetrics activityId threadUrl (Just endTime) costCents Nothing
+
case exitCode of
Exit.ExitSuccess -> do
TaskCore.logActivity tid TaskCore.Reviewing Nothing