From 83ff4b622be49762491dac216ab8df374b24cd74 Mon Sep 17 00:00:00 2001 From: Ben Sima Date: Thu, 27 Nov 2025 10:59:38 -0500 Subject: 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 --- Omni/Agent/Log.hs | 4 ++++ Omni/Agent/Worker.hs | 15 +++++++++++++-- 2 files changed, 17 insertions(+), 2 deletions(-) (limited to 'Omni/Agent') diff --git a/Omni/Agent/Log.hs b/Omni/Agent/Log.hs index b1020c5..55bc1e2 100644 --- a/Omni/Agent/Log.hs +++ b/Omni/Agent/Log.hs @@ -72,6 +72,10 @@ update f = do modifyIORef' currentStatus f render +-- | Get the current status +getStatus :: IO Status +getStatus = readIORef currentStatus + -- | Set the activity message updateActivity :: Text -> IO () updateActivity msg = update (\s -> s {statusActivity = msg}) 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/" <>) do TaskCore.logActivity tid TaskCore.Reviewing Nothing -- cgit v1.2.3