From dbef6906294061d2a2640c6d956cc2f386b75f14 Mon Sep 17 00:00:00 2001 From: majian Date: Fri, 6 Mar 2026 16:00:59 +0800 Subject: [PATCH] feat(heartbeat): add AI and human line changes tracking fields Add `ai_line_changes` and `human_line_changes` fields to the Heartbeat model, WakaTime v1 compat layer, and swagger docs to support tracking AI-assisted vs human code contributions. Co-Authored-By: Claude Opus 4.6 --- models/compat/wakatime/v1/heartbeat.go | 79 ++++++++++++++------------ models/heartbeat.go | 2 + static/docs/swagger.yaml | 8 +++ 3 files changed, 52 insertions(+), 37 deletions(-) diff --git a/models/compat/wakatime/v1/heartbeat.go b/models/compat/wakatime/v1/heartbeat.go index f5c69f83..f75771ed 100644 --- a/models/compat/wakatime/v1/heartbeat.go +++ b/models/compat/wakatime/v1/heartbeat.go @@ -1,11 +1,12 @@ package v1 import ( - "github.com/duke-git/lancet/v2/stream" "net/http" "strconv" "time" + "github.com/duke-git/lancet/v2/stream" + "github.com/muety/wakapi/models" ) @@ -59,24 +60,26 @@ type HeartbeatResponseData struct { // that is actually required for the import type HeartbeatEntry struct { - Id string `json:"id"` - Branch string `json:"branch"` - Category string `json:"category"` - Entity string `json:"entity"` - IsWrite bool `json:"is_write"` - Language string `json:"language"` - Project string `json:"project"` - Time float64 `json:"time"` - Type string `json:"type"` - UserId string `json:"user_id"` - MachineNameId string `json:"machine_name_id"` - UserAgentId string `json:"user_agent_id"` - Lines int `json:"lines"` - LineNo int `json:"lineno"` - CursorPos int `json:"cursorpos"` - LineDeletions int `json:"line_deletions"` - LineAdditions int `json:"line_additions"` - CreatedAt time.Time `json:"created_at"` + Id string `json:"id"` + Branch string `json:"branch"` + Category string `json:"category"` + Entity string `json:"entity"` + IsWrite bool `json:"is_write"` + Language string `json:"language"` + Project string `json:"project"` + Time float64 `json:"time"` + Type string `json:"type"` + UserId string `json:"user_id"` + MachineNameId string `json:"machine_name_id"` + UserAgentId string `json:"user_agent_id"` + Lines int `json:"lines"` + LineNo int `json:"lineno"` + CursorPos int `json:"cursorpos"` + LineDeletions int `json:"line_deletions"` + LineAdditions int `json:"line_additions"` + CreatedAt time.Time `json:"created_at"` + AILineChanges int `json:"ai_line_changes,omitempty" hash:"ignore"` + HumanLineChanges int `json:"human_line_changes,omitempty" hash:"ignore"` } func HeartbeatsToCompat(entries []*models.Heartbeat) []*HeartbeatEntry { @@ -84,24 +87,26 @@ func HeartbeatsToCompat(entries []*models.Heartbeat) []*HeartbeatEntry { for i := 0; i < len(entries); i++ { entry := entries[i] out[i] = &HeartbeatEntry{ - Id: strconv.FormatUint(entry.ID, 10), - Branch: entry.Branch, - Category: entry.Category, - Entity: entry.Entity, - IsWrite: entry.IsWrite, - Language: entry.Language, - Project: entry.Project, - Time: float64(entry.Time.T().Unix()), - Type: entry.Type, - UserId: entry.UserID, - MachineNameId: entry.Machine, - UserAgentId: entry.UserAgent, - Lines: entry.Lines, - LineNo: entry.LineNo, - LineAdditions: entry.LineAdditions, - LineDeletions: entry.LineDeletions, - CursorPos: entry.CursorPos, - CreatedAt: entry.CreatedAt.T(), + Id: strconv.FormatUint(entry.ID, 10), + Branch: entry.Branch, + Category: entry.Category, + Entity: entry.Entity, + IsWrite: entry.IsWrite, + Language: entry.Language, + Project: entry.Project, + Time: float64(entry.Time.T().Unix()), + Type: entry.Type, + UserId: entry.UserID, + MachineNameId: entry.Machine, + UserAgentId: entry.UserAgent, + Lines: entry.Lines, + LineNo: entry.LineNo, + LineAdditions: entry.LineAdditions, + LineDeletions: entry.LineDeletions, + CursorPos: entry.CursorPos, + CreatedAt: entry.CreatedAt.T(), + AILineChanges: entry.AILineChanges, + HumanLineChanges: entry.HumanLineChanges, } } return out diff --git a/models/heartbeat.go b/models/heartbeat.go index 8dd487f6..4b68e4d6 100644 --- a/models/heartbeat.go +++ b/models/heartbeat.go @@ -40,6 +40,8 @@ type Heartbeat struct { LineDeletions int `json:"line_deletions,omitempty" hash:"ignore"` LineAdditions int `json:"line_additions,omitempty" hash:"ignore"` ProjectRootCount int `json:"project_root_count,omitempty" hash:"ignore"` + AILineChanges int `json:"ai_line_changes,omitempty" hash:"ignore"` + HumanLineChanges int `json:"human_line_changes,omitempty" hash:"ignore"` } func (h *Heartbeat) Valid() bool { diff --git a/static/docs/swagger.yaml b/static/docs/swagger.yaml index 0d9c046b..7e6df130 100644 --- a/static/docs/swagger.yaml +++ b/static/docs/swagger.yaml @@ -40,6 +40,10 @@ definitions: type: integer line_deletions: type: integer + ai_line_changes: + type: integer + human_line_changes: + type: integer lineno: type: integer lines: @@ -198,6 +202,10 @@ definitions: type: integer line_deletions: type: integer + ai_line_changes: + type: integer + human_line_changes: + type: integer lineno: type: integer lines: