Add WakaTime-compatible profile and summary endpoints - #1569
Add WakaTime-compatible profile and summary endpoints#1569skyfallwastaken wants to merge 3 commits into
Conversation
Greptile SummaryAdds authenticated WakaTime-compatible profile and daily-summary endpoints, including timezone-aware aggregation and AI activity counters.
Confidence Score: 5/5The PR appears safe to merge. No blocking failure remains; the previously reported cross-project attribution issue is corrected by assigning each interval to its preceding heartbeat and is covered by the updated regression test. Important Files Changed
Sequence DiagramsequenceDiagram
participant Client as WakaTime Client
participant Controller as HackatimeController
participant Service as WakatimeService
participant Heartbeats as Heartbeat Aggregation
participant DB as PostgreSQL
Client->>Controller: GET /users/current/summaries
Controller->>Controller: Authenticate and validate dates/timezone
Controller->>Service: generate_daily_summaries
Service->>Heartbeats: daily_activity_summary_rows
Heartbeats->>DB: Query ordered heartbeat intervals
DB-->>Heartbeats: Daily project and AI aggregates
Heartbeats-->>Service: Aggregated rows
Service-->>Controller: WakaTime-compatible summary
Controller-->>Client: 200 JSON
Reviews (3): Last reviewed commit: "Attribute summary gaps to preceding hear..." | Re-trigger Greptile |
| WHEN LAG(time) OVER (PARTITION BY #{local_date_sql} ORDER BY time, id) IS NULL THEN 0 | ||
| ELSE LEAST(time - LAG(time) OVER (PARTITION BY #{local_date_sql} ORDER BY time, id), #{timeout}) |
There was a problem hiding this comment.
Cross-project gaps are misattributed
When a user alternates between projects or AI models during one day, the date-only LAG window assigns each cross-group gap to the later heartbeat's project and model, causing incorrect project and AI-model duration breakdowns.
Knowledge Base Used: Heartbeat Ingest
Prompt To Fix With AI
This is a comment left during a code review.
Path: lib/wakatime_service.rb
Line: 213-214
Comment:
**Cross-project gaps are misattributed**
When a user alternates between projects or AI models during one day, the date-only `LAG` window assigns each cross-group gap to the later heartbeat's project and model, causing incorrect project and AI-model duration breakdowns.
**Knowledge Base Used:** [Heartbeat Ingest](https://app.greptile.com/mahadk/-/custom-context/knowledge-base/hackclub/hackatime/-/docs/heartbeat-ingest.md)
---
For each issue above, determine whether it is valid and should be fixed. If so, fix it directly.
Summary of the problem
Hackatime's WakaTime-compatible API returned 404 responses for the current user profile and daily summary routes required by clients using a custom instance. This caused correctly configured clients to report that the provider was unavailable.
Describe your changes
/api/hackatime/v1Screenshots / Media
N/A