/** * SQL for the system overview tool. * * All queries are SELECT-only, read-safe, and index-backed. * They target only lt_* tables — no HotMesh schema dependencies. * $1 is always the period interval (e.g., '24 hours'). */ /** Escalation queue pressure — aging buckets, claim status, period counts. */ export declare const OVERVIEW_ESCALATION_TRIAGE = "\n SELECT\n COUNT(*) FILTER (WHERE status = 'pending')::int AS pending,\n COUNT(*) FILTER (WHERE status = 'pending'\n AND assigned_to IS NOT NULL AND assigned_until > NOW())::int AS claimed,\n COUNT(*) FILTER (WHERE status = 'pending'\n AND (assigned_to IS NULL OR assigned_until <= NOW()))::int AS unclaimed,\n COUNT(*) FILTER (WHERE status = 'pending'\n AND created_at < NOW() - INTERVAL '30 minutes')::int AS aging_30m,\n COUNT(*) FILTER (WHERE status = 'pending'\n AND created_at < NOW() - INTERVAL '1 hour')::int AS aging_1h,\n COUNT(*) FILTER (WHERE status = 'pending'\n AND created_at < NOW() - INTERVAL '24 hours')::int AS aging_24h,\n COALESCE(\n EXTRACT(EPOCH FROM (NOW() - MIN(created_at) FILTER (\n WHERE status = 'pending'\n AND (assigned_to IS NULL OR assigned_until <= NOW())\n )))::int / 60, 0\n ) AS oldest_unclaimed_minutes,\n COUNT(*) FILTER (WHERE created_at > NOW() - $1::interval)::int AS created_period,\n COUNT(*) FILTER (WHERE resolved_at > NOW() - $1::interval)::int AS resolved_period\n FROM lt_escalations"; /** Escalation breakdown by role (pending only). */ export declare const OVERVIEW_ESCALATION_BY_ROLE = "\n SELECT role,\n COUNT(*)::int AS pending,\n COUNT(*) FILTER (WHERE assigned_to IS NOT NULL AND assigned_until > NOW())::int AS claimed\n FROM lt_escalations\n WHERE status = 'pending'\n GROUP BY role\n ORDER BY COUNT(*) DESC\n LIMIT 10"; /** Task creation and completion counts for 1h and the configurable period. */ export declare const OVERVIEW_TASK_THROUGHPUT = "\n SELECT\n COUNT(*) FILTER (WHERE status = 'pending')::int AS pending,\n COUNT(*) FILTER (WHERE status = 'in_progress')::int AS in_progress,\n COUNT(*) FILTER (WHERE status = 'failed')::int AS failed,\n COUNT(*) FILTER (WHERE created_at > NOW() - INTERVAL '1 hour')::int AS created_1h,\n COUNT(*) FILTER (WHERE completed_at > NOW() - INTERVAL '1 hour')::int AS completed_1h,\n COUNT(*) FILTER (WHERE created_at > NOW() - $1::interval)::int AS created_period,\n COUNT(*) FILTER (WHERE completed_at > NOW() - $1::interval)::int AS completed_period,\n COUNT(*) FILTER (WHERE status = 'failed'\n AND created_at > NOW() - INTERVAL '1 hour')::int AS failed_1h\n FROM lt_tasks"; /** Hourly escalation creation within the period. */ export declare const OVERVIEW_ESCALATION_TRENDS = "\n SELECT date_trunc('hour', created_at) AS hour, COUNT(*)::int AS created\n FROM lt_escalations\n WHERE created_at > NOW() - $1::interval\n GROUP BY 1 ORDER BY 1"; /** Hourly task completion within the period. */ export declare const OVERVIEW_TASK_TRENDS = "\n SELECT date_trunc('hour', completed_at) AS hour, COUNT(*)::int AS completed\n FROM lt_tasks\n WHERE completed_at IS NOT NULL AND completed_at > NOW() - $1::interval\n GROUP BY 1 ORDER BY 1"; /** Hourly resolution velocity — created vs resolved. */ export declare const OVERVIEW_RESOLUTION_TRENDS = "\n SELECT\n gs AS hour,\n COALESCE(c.created, 0)::int AS created,\n COALESCE(r.resolved, 0)::int AS resolved\n FROM generate_series(\n date_trunc('hour', NOW() - $1::interval),\n date_trunc('hour', NOW()),\n INTERVAL '1 hour'\n ) AS gs\n LEFT JOIN (\n SELECT date_trunc('hour', created_at) AS h, COUNT(*)::int AS created\n FROM lt_escalations WHERE created_at > NOW() - $1::interval\n GROUP BY 1\n ) c ON c.h = gs\n LEFT JOIN (\n SELECT date_trunc('hour', resolved_at) AS h, COUNT(*)::int AS resolved\n FROM lt_escalations WHERE resolved_at > NOW() - $1::interval\n GROUP BY 1\n ) r ON r.h = gs\n ORDER BY gs"; /** MCP server and tool counts. */ export declare const OVERVIEW_MCP_INFRASTRUCTURE = "\n SELECT\n COUNT(*)::int AS total,\n COUNT(*) FILTER (WHERE status = 'connected')::int AS connected,\n COALESCE(SUM(jsonb_array_length(tool_manifest)) FILTER (WHERE tool_manifest IS NOT NULL), 0)::int AS total_tools\n FROM lt_mcp_servers"; /** Compiled workflow counts. */ export declare const OVERVIEW_COMPILED_WORKFLOWS = "\n SELECT\n COUNT(*)::int AS total,\n COUNT(*) FILTER (WHERE status = 'active')::int AS active\n FROM lt_yaml_workflows"; /** Agent health snapshot. */ export declare const OVERVIEW_AGENT_HEALTH = "\n SELECT\n COUNT(*)::int AS total,\n COUNT(*) FILTER (WHERE status = 'active')::int AS active,\n COUNT(*) FILTER (WHERE status = 'paused')::int AS paused,\n COUNT(*) FILTER (WHERE status = 'error')::int AS error,\n COUNT(*) FILTER (WHERE last_run_at IS NULL\n OR last_run_at < NOW() - INTERVAL '7 days')::int AS stale\n FROM lt_agents"; /** Registered workflow config count. */ export declare const OVERVIEW_WORKFLOW_CONFIGS = "\n SELECT COUNT(*)::int AS total FROM lt_config_workflows"; /** Process summary — grouped by origin_id within the period. */ export declare const OVERVIEW_PROCESS_SUMMARY = "\n SELECT\n COUNT(DISTINCT origin_id)::int AS total,\n COUNT(DISTINCT origin_id) FILTER (\n WHERE status IN ('pending', 'in_progress'))::int AS active,\n COUNT(DISTINCT origin_id) FILTER (\n WHERE status = 'completed')::int AS completed,\n COUNT(DISTINCT origin_id) FILTER (\n WHERE status = 'needs_intervention')::int AS escalated\n FROM lt_tasks\n WHERE origin_id IS NOT NULL\n AND created_at > NOW() - $1::interval";