Skip to content

feat(activity): add activity tracking and LLM cost visibility#131

Merged
danielnaab merged 9 commits intomainfrom
story-119/activity-tracking
May 7, 2026
Merged

feat(activity): add activity tracking and LLM cost visibility#131
danielnaab merged 9 commits intomainfrom
story-119/activity-tracking

Conversation

@danielnaab
Copy link
Copy Markdown
Member

Summary

  • Adds a new src/services/activity/ service that logs platform events (LLM calls, project creation, sign-in, PDF upload) with full user/project/operation attribution
  • Implements CLI commands (bun run cli activity summary|events|digest) for querying activity and posting daily Slack digests
  • Adds NixOS systemd timer for automated daily digest at 6am

Story

Closes #119

Acceptance Criteria

  • LLM API calls are logged with user attribution, token counts, and cost estimates
  • An admin can view a summary of platform usage (who, what, how much)
  • Activity logs are queryable for debugging and auditing
  • The tracking implementation does not noticeably impact request latency

Test Plan

  • bun run check passes (1367 tests, 0 failures)
  • 17 new tests covering activity store, instrumentation, non-LLM events, pricing, and CLI formatting
  • Type check clean (tsc --noEmit)
  • Deployed and verified on branch (activity CLI commands produce expected output)
  • Verify daily digest posts to Slack (trigger manually with bun run cli activity digest)

Review Notes

  • Architecture: New service follows existing patterns (factory function, index.ts boundary, WAL mode SQLite). Fire-and-forget tracking ensures zero latency impact.
  • Cost estimation: Raw tokens stored, cost computed at query time from a codebase price table. Supports retroactive recalculation when prices change.
  • Scope: Web UI for activity viewing intentionally deferred to a future story. CLI + Slack covers all ACs.
  • Pre-existing issue: test/layout-tokens.test.ts fails without dist/styles.css build artifact — unrelated to this branch.

danielnaab added 9 commits May 7, 2026 04:37
Foundation service for story #119 (activity tracking and LLM cost
visibility). SQLite-backed store records events with timestamps,
supports filtered queries, and computes usage summaries with
estimated costs from Bedrock pricing.
Fire-and-forget helper that records LLM usage (model, input/output
tokens, duration) to the activity store. Designed to be called after
each generateText() invocation without affecting the hot path.
Wrap generateText() calls in extraction, shaping, and filling with
timing and token tracking. The activityStore is created in server.tsx
and threaded through registries and agent constructors.

Instrumented operations:
- extraction (Step 1 PDF analysis)
- extraction-formspec (Step 2 FormSpec generation)
- extraction-fieldmapping (Step 3 AcroForm field mapping)
- shaping (form structure editing)
- filling (conversational form filling)

All tracking is fire-and-forget — failures log to stderr without
affecting the user-facing operation.
Add activity tracking calls for non-LLM events:
- sign_in: tracked in auth callback after successful authentication
- project_created: tracked for PDF upload, fixture, and corpus project creation
- pdf_uploaded: tracked when a user uploads a PDF file

Thread activityStore to createAuthRoutes via an optional options parameter.
Adds the `activity` CLI command with three subcommands:
- `summary` — shows usage summary with cost breakdowns by user/operation/project
- `events` — lists raw activity events with filtering options
- `digest` — posts daily usage digest to Slack via the notify service
…ntation

- Pass userId to extraction options in project-service fireAndForgetExtraction
- Add userId/projectId to shaping request in edit route intent handler
- Add userId/projectId to filling context in both chat view and chat message handlers
- Instrument tool-use extraction variant with trackLlmCall timing
- Pass activityStore through extraction registry to tool-use variant
- Complete pricing table with all model IDs used in the codebase
@danielnaab danielnaab force-pushed the story-119/activity-tracking branch from e111224 to c89f55a Compare May 7, 2026 04:38
@danielnaab danielnaab temporarily deployed to story-119-activity-tracking May 7, 2026 04:38 Inactive
@danielnaab danielnaab merged commit 537bb68 into main May 7, 2026
2 of 4 checks passed
@danielnaab danielnaab deleted the story-119/activity-tracking branch May 7, 2026 06:53
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.

Add activity tracking and LLM cost visibility

1 participant