Skip to content

feat(api): add chat read tools for summary/retrospective/metrics (#82) - #180

Merged
thomasluizon merged 1 commit into
mainfrom
issue-82
Jun 5, 2026
Merged

feat(api): add chat read tools for summary/retrospective/metrics (#82)#180
thomasluizon merged 1 commit into
mainfrom
issue-82

Conversation

@thomasluizon

Copy link
Copy Markdown
Owner

@
Adds three read-only IAiTool implementations to the in-app chat agent, each a thin wrapper over an existing MediatR query:

  • get_daily_summary -> GetDailySummaryQuery (date range defaults to user-today via IUserDateService)
  • get_retrospective -> GetRetrospectiveQuery (period -> date-range, mirroring HabitsController.GetRetrospective)
  • get_habit_metrics -> GetHabitMetricsQuery (validates habit_id as a GUID at the boundary)

All three are IsReadOnly => true. PayGate / failure Results surface as ToolResult(false, Error: ...) (mirroring GetGamificationOverviewTool) rather than being swallowed — get_daily_summary for non-Pro / ai_summary off, get_retrospective for non-YearlyPro / ai_retrospective off.

Registered in DI (ServiceCollectionExtensions.cs) and mapped onto the existing HabitMetricsRead / DailySummaryRead / RetrospectiveRead catalog capabilities via their chatTools arrays (no new capabilities; risk_class: Low, confirmation: None unchanged).

Tests

  • New unit tests per tool (success, PayGate/failure propagation, arg derivation) under tests/Orbit.Application.Tests/Chat/Tools/.
  • Updated ChatToolMetadataTests.cs (names/descriptions/schemas).
  • EveryChatTool_IsMappedToTheCatalog (Infrastructure.Tests) auto-discovers the new tools and stays green.
  • dotnet build clean; Application.Tests (1689) + Infrastructure.Tests (917) all pass.

Refs thomasluizon/orbit-ui-mobile#82

Stacked on #175 (#79) — shares the chat catalog/DI files (ServiceCollectionExtensions.cs + AgentCatalogService.cs). Base is issue-79; review/merge #175 first.

🤖 Generated with Claude Code
@

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three clean read-only IAiTool wrappers over existing MediatR queries. User scoping is enforced at the query layer (GetHabitMetricsQuery filters by both HabitId and UserId in the DB predicate; the other two pass UserId through to their handlers). All three use IUserDateService.GetUserTodayAsync for date defaulting, in full compliance with the timezone hard-rule. PayGate/failure Results surface correctly as ToolResult(false, Error: ...) rather than being swallowed, matching the existing GamificationOverview pattern. DI registration and catalog wiring are minimal and correct. Unit test coverage is solid — success, PayGate propagation, and argument-derivation cases are all present for each tool.

Base automatically changed from issue-79 to main June 4, 2026 23:57
Add three read-only IAiTool implementations that wrap existing MediatR
queries so in-app chat users can ask for their daily summary, a
retrospective, or a single habit's metrics:

- get_daily_summary -> GetDailySummaryQuery (defaults dates to user-today)
- get_retrospective -> GetRetrospectiveQuery (period -> date-range)
- get_habit_metrics -> GetHabitMetricsQuery (GUID-validated)

PayGate / failure results surface as ToolResult(false, Error: ...) rather
than being swallowed. Registered in DI and mapped onto the existing
HabitMetricsRead / DailySummaryRead / RetrospectiveRead catalog
capabilities via chatTools.

Refs thomasluizon/orbit-ui-mobile#82

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@thomasluizon
thomasluizon merged commit 865cb86 into main Jun 5, 2026
2 checks passed
@thomasluizon
thomasluizon deleted the issue-82 branch June 5, 2026 00:04

@claude claude Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Three clean read-only IAiTool wrappers over existing MediatR queries. All three use IUserDateService.GetUserTodayAsync for date defaulting (timezone hard-rule satisfied), pass userId through to their queries (user scoping enforced at the query layer), and surface PayGate/failure Results as ToolResult(false, Error: ...) rather than swallowing them — consistent with the GamificationOverview pattern. GUID boundary validation in GetHabitMetricsTool is correct. Catalog wiring maps onto the existing DailySummaryRead/RetrospectiveRead/HabitMetricsRead capabilities with no new capabilities added. Unit test coverage is solid across success, PayGate propagation, and argument-derivation cases for all three tools.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant