monoscope/static/migrations
Anthony Alaribe bf6faa8cd9
Improve anomaly detail page layout and add AI chat (#249)
* Improve anomaly detail page layout and add AI chat

- Move action buttons (acknowledge, archive) to navbar as page actions
- Remove surface-raised from header, add more breathing room
- Update button styles to match navbar patterns (btn-sm)
- Add time stat boxes showing first/last seen with compact formatting
- Add AI chat functionality for investigating anomalies
- Add side-chevron-left icon (without box) for collapse toggle
- Use new icon for trace panel collapse button

* Auto-format code with fourmolu

* Refactor AI chat to use agentic tools and DB-persisted history

- Extend AgenticConfig with conversationId and conversationType fields
- Add runAgenticChatWithHistory for DB-backed conversations
- Refactor Anomalies.hs to use agentic query system (access to 8 tools)
- Add Slack/Discord thread persistence in DB instead of repeated API calls
- Add deterministic UUID5 helpers for thread conversation IDs
- One-time migration pattern: first thread access migrates from external API
- Log Explorer remains stateless for low latency

* Auto-format code with fourmolu

* Fix security issues and improve AI chat persistence

Security fixes:
- Use executeSecuredQuery for dashboard constants/variables SQL
- Add project_id filtering to prevent cross-project data access

AI chat improvements:
- Save user message before AI call for complete history
- Persist assistant response on error and parse failure paths
- Fix race condition in getOrCreateConversation (use listToMaybe)

Code style (CLAUDE.md):
- Remove unnecessary $ before lambdas in Anomalies.hs
- Clean up unused imports in Dashboards.hs

* Auto-format code with fourmolu

* Refactor time display and error handling for cleaner code

- Add abbreviateUnit helper with LambdaCase for cleaner word mapping
- Simplify compactTimeAgo using word-based abbreviation
- Refactor timeStatBox_ to use pattern matching on T.words
- Replace fromMaybe.error with explicit pattern match in getOrCreateConversation

* Auto-format code with fourmolu

* Fix hlint warnings in Anomalies and AI modules

- Replace T.unwords/T.words/T.unlines with Relude equivalents
- Simplify lambdas to operator sections
- Replace pure () with pass

* Optimize AI and anomaly code with better data structures

- Use Map for O(1) time unit abbreviation lookup in Anomalies.hs
- Extract dangerous SQL patterns to top-level constant with additional
  security patterns (copy, execute, explain, set)
- Replace V.toList conversions with pure Vector operations using vIntercalate
- Use V.take instead of take after V.toList for efficiency
- Reorder migration files for correct dependency order

* Auto-format code with fourmolu

* Optimize AI and anomaly code with better data structures

- Use Map for O(1) time unit abbreviation lookup in Anomalies.hs
- Extract dangerous SQL patterns to top-level constant with additional
  security patterns (copy, execute, explain, set)
- Replace V.toList conversions with pure Vector operations using vIntercalate
- Use V.take instead of take after V.toList for efficiency
- Reorder migration files for correct dependency order

* Auto-format code with fourmolu

* Use chunksOf and parseMaybe for cleaner code in Anomalies.hs

- Replace manual groupMessages recursion with chunksOf from extra
- Use parseMaybe from aeson instead of case on fromJSON result

* Fix security and code quality issues

- Fix SQL injection risk: wrap query in transaction with READ ONLY mode,
  add comment markers (--,/*,*/) to dangerous patterns validation
- Replace unsafe error call with safe fromMaybe in getOrCreateConversation
- Extract textToConversationId helper for cleaner UUID V5 generation
- Remove Control.Lens import, use record update syntax instead
- Add manage_updated_at trigger migration for ai_conversations table
- Update parser test expectations to match current output format

* Auto-format code with fourmolu

* Fix bugs and improve code quality in anomaly/issues modules

- Fix race condition in getOrCreateConversation: fail explicitly if
  RETURNING clause doesn't return a row instead of silent fallback
- Replace Map lookup with pattern matching for time unit abbreviation
- Fix V.take order: take before map for better performance
- Make chat history pairing more robust with explicit recursion
- Add doctests for abbreviateUnit function
- Remove obvious comments, keep only meaningful ones
- Add updated_at trigger for ai_conversations table

* Auto-format code with fourmolu

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
History 2026-01-03 18:32:18 +01:00
..
0001_create_monoscope_tables.sql Alerts view & Error details page (#225) 2025-12-23 17:54:20 +01:00
0002_logs_traces_metrics.sql add error column to otel logs and spans table 2025-09-06 18:28:18 +00:00
0003_facets_table.sql unit tests pass. checkpoint towards passing integration tests 2025-07-03 15:15:11 +02:00
0006_add_llm_enhancement_tracking.sql fixes for integration tests 2025-10-18 02:17:33 +02:00
0007_rebuild_issues_table.sql fix migration files 2025-08-25 21:47:57 +00:00
0008_use_non_defferable_contraint_on_issues.sql fix log pattern extraction memory usage 2025-09-29 10:12:42 +00:00
0009_make_retention_policy_30.sql increase retention policy to 30 days 2025-08-30 20:08:52 +00:00
0010_requbild_ers_view.sql fix endpoints list page 2025-09-01 10:03:39 +00:00
0011_host_request_stats.sql make apicatalog a materialized view 2025-09-01 11:29:52 +00:00
0012_drop_materialized_views.sql drop views 2025-09-01 14:59:02 +00:00
0013_log_patterns.sql Log patterns (#200) 2025-09-27 10:58:23 +00:00
0014_alerts_config.sql configure endoins and error alerts 2025-10-02 10:40:45 +00:00
0015_summary_pattern.sql generate patterns for summary 2025-10-12 05:58:08 +00:00
0016_drop_overly_restrictive_issues_constraint.sql Fix issues table constraint to allow multiple query alerts 2025-11-15 05:59:08 +00:00
0016_reports_start_and_end_time.sql New Reports UI (#207) 2025-11-13 07:45:20 +00:00
0017_teams_table.sql Teams rebased (#233) 2025-12-18 23:38:00 +01:00
0018_store_monitor_runs_as_events.sql Alerts view & Error details page (#225) 2025-12-23 17:54:20 +01:00
0019_add_trace_id.sql Alerts view & Error details page (#225) 2025-12-23 17:54:20 +01:00
0020_github_sync.sql Github 2-way sync with a repo (#244) 2025-12-26 01:19:12 +01:00
0021_move_monitors_to_haskell.sql move query monitors to Haskell implementation 2025-12-27 22:31:07 +00:00
0022_query_cache.sql Query cache (#252) 2026-01-01 14:51:17 +01:00
0023_anomaly_chat_messages.sql Improve anomaly detail page layout and add AI chat (#249) 2026-01-03 18:32:18 +01:00
0024_ai_conversations_updated_at_trigger.sql Improve anomaly detail page layout and add AI chat (#249) 2026-01-03 18:32:18 +01:00