2.9 KiB
id, title, status, wave, depends_on, plan, spec, adr
| id | title | status | wave | depends_on | plan | spec | adr |
|---|---|---|---|---|---|---|---|
| 02-session-loc-aggregation | Per-session LOC aggregation (committed + peak-pending) | done | 1 | plan.md | ../../../specs/plugins/requirements/plugins.md | ../../../decisions/0043-plugin-host-data-api.md |
Task 02: Per-session LOC aggregation (committed + peak-pending)
Add the one net-new read-only query the Host data API needs: per-session code
stats. No existing method computes this. internal/analytics/repository/sqlite/ stats.go aggregates git stats at workspace and per-repository granularity only,
and the peak-pending snapshot aggregation exists nowhere in-tree.
Scope
Add a repository method (recommended home: internal/analytics/repository/sqlite/,
alongside GetGitStats/GetRepositoryStats) returning, per session id:
lines_added_committed=SUM(insertions)overtask_session_commits.lines_deleted_committed=SUM(deletions).lines_added_peak_pending=MAXover each snapshot'sSUM(json_extract(json_each(files).value,'$.additions'))fromtask_session_git_snapshots(peak, not latest — the latest is usually a clean tree).lines_deleted_peak_pending= the deletions equivalent.
Mirror the SQL in the agent-stats plugin
(/home/jcfs/.kandev/tasks/tokens-per-task-loc_9tk/kandev-plugin-agent-stats/server/stats.go,
sessionsQuery). Use internal/db/dialect helpers (JSONExtract, etc.) so the
query is portable to Postgres. Support filtering by a session-id set and/or
workspace, plus a limit/offset (or cursor bound) for pagination. Expose it via a
service method so the Host handler (task-04) calls the service, not the repository.
Acceptance
- New repository + service method returns per-session committed sums and the
peak-pending
MAXsemantics, filterable by session ids / workspace. - Peak-pending uses the peak snapshot, not the latest, and does not double-count
committed work (matches
effectiveLinesintent in the source plugin). - Table-driven SQLite test with commits + multiple snapshots asserts both.
Verification
cd apps/backend && go test ./internal/analytics/...
Files likely touched
apps/backend/internal/analytics/repository/sqlite/stats.goapps/backend/internal/analytics/models/(newSessionCodeStatsmodel)- analytics service file exposing the method
apps/backend/internal/analytics/repository/sqlite/*_test.go
Inputs
- Source SQL: agent-stats
server/stats.gosessionsQuery(committed sums + snapshot peak). - Patterns:
GetGitStats/buildRepositoryStatsQueryininternal/analytics/repository/sqlite/stats.go;dialecthelpers. - Spec: "Host data API" →
ListSessionCodeStatsrow.
Dependencies
None. Independent of the proto task (pure Go/SQL).
Output contract
Summary, method signatures added, chosen home (analytics vs task repo), test
result, portability notes (SQLite/Postgres), and status update here + in plan.md.