Skip to content

feat(telemetry): rich interaction telemetry schema + ingestion + Monaco capture [STORY-055]#20

Merged
khoks merged 1 commit intomainfrom
story/055-rich-interaction-telemetry-schema
Apr 28, 2026
Merged

feat(telemetry): rich interaction telemetry schema + ingestion + Monaco capture [STORY-055]#20
khoks merged 1 commit intomainfrom
story/055-rich-interaction-telemetry-schema

Conversation

@khoks
Copy link
Copy Markdown
Owner

@khoks khoks commented Apr 28, 2026

Summary

  • New interactions table (Drizzle migration 0003_interactions.sql) with a 9-value interaction_type pgEnum + episodes.interactions_summary jsonb for fast tutor-time reads. user_id and episode_id are nullable until auth lands (STORY-005).
  • @learnpro/shared owns the wire protocol: InteractionEventSchema discriminated union over the 9 event kinds, InteractionsBatchSchema with a 200-event cap, abstract InteractionStore interface. @learnpro/db ships DrizzleInteractionStore (single-round-trip bulk insert).
  • POST /v1/interactions Fastify endpoint Zod-validates, stamps server t, returns 202/400/503. Default NoopInteractionStore so tests + dev don't need a DB.
  • Browser side: InteractionBatcher (size + idle flush, keepalive: true), pure CursorFocusTracker + RevertDetector, useInteractionCapture React hook wired into the playground Monaco editor. Voice opt-in toggle UI lands; voice capture defers to STORY-056 (redaction prerequisite).

ACs landed (4 of 6)

  • interactions schema + migration
  • ✅ Cursor focus / edit / revert capture (voice opt-in toggle UI; capture deferred)
  • ✅ Batched POST endpoint with Zod validation
  • ✅ Smoke test coverage (35 new tests across 5 packages, 5 of them DATABASE_URL-gated integration tests against real Postgres)
  • ✅ No editor perf regression (O(1) per cursor move; trackers held in useRef)
  • ⏳ Voice transcript redaction → STORY-056 as planned

Test plan

  • pnpm -r typecheck clean across the workspace
  • pnpm -r lint clean
  • pnpm -r test — all green (237 passed, 14 skipped, 0 failed)
  • pnpm format:check clean
  • Integration tests pass locally with DATABASE_URL=postgresql://learnpro:learnpro@localhost:5432/learnpro pnpm --filter @learnpro/db test
  • Manual playground smoke (defer until apps/api gets a real DB client + auth in STORY-005)

🤖 Generated with Claude Code

…co capture [STORY-055]

Adds the `interactions` table, Zod wire schemas, batched ingestion endpoint, and
client-side cursor / edit / revert capture wired into the playground Monaco editor.
Voice opt-in toggle UI lands; voice capture itself is deferred to STORY-056 (raw
transcripts can't be persisted without redaction).

- packages/db: migration `0003_interactions.sql` adds the `interaction_type` pgEnum
  (9 event kinds), the `interactions` table with `(episode_id, t)` and `(user_id, t)`
  indexes, and `episodes.interactions_summary jsonb`. `DrizzleInteractionStore`
  bulk-inserts a batch in a single round-trip; 5 DATABASE_URL-gated integration tests.
- packages/shared: `InteractionEventSchema` discriminated union, `InteractionsBatchSchema`
  with a 200-event cap, and the abstract `InteractionStore` interface. 12 unit tests.
- apps/api: `POST /v1/interactions` Zod-validates, stamps server `t`, returns 202 / 400 /
  503; `NoopInteractionStore` is the default so tests + the dev playground don't need a
  DB. 6 endpoint tests.
- apps/web: Next.js proxy at `/api/interactions` mirrors the sandbox proxy. Pure
  `InteractionBatcher` (size + idle flush, `keepalive: true`), pure `CursorFocusTracker`
  (debounced cursor_focus emission), pure `RevertDetector` (sliding 30 s snapshot
  window), and the `useInteractionCapture` React hook that wires Monaco's
  `onDidChangeCursorPosition` + `onDidChangeModelContent` to those trackers. Voice
  opt-in toggle in PlaygroundClient. 24 unit tests.

3 of 6 ACs land in this PR; voice redaction defers to STORY-056 per the spec.

Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>
@khoks khoks merged commit 4c88381 into main Apr 28, 2026
1 check passed
@khoks khoks deleted the story/055-rich-interaction-telemetry-schema branch April 28, 2026 05:42
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