monoscope/test
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
..
doctests Github 2-way sync with a repo (#244) 2025-12-26 01:19:12 +01:00
golden New editor and AI query support (#172) 2025-05-25 07:53:20 +02:00
integration Query cache (#252) 2026-01-01 14:51:17 +01:00
unit Improve anomaly detail page layout and add AI chat (#249) 2026-01-03 18:32:18 +01:00