Skip to content

feat: external annotations API with real-time SSE#400

Open
backnotprop wants to merge 2 commits intomainfrom
feat/review-annotations-api
Open

feat: external annotations API with real-time SSE#400
backnotprop wants to merge 2 commits intomainfrom
feat/review-annotations-api

Conversation

@backnotprop
Copy link
Owner

Summary

  • Adds a general-purpose External Annotations API so any external program can push annotations into a live Plannotator review session via HTTP and have them appear in the browser UI in real-time via Server-Sent Events
  • Shared core store logic in packages/shared/ ensures identical behavior between Bun and Pi servers — both are thin HTTP adapters over the same runtime-agnostic code
  • Frontend hook uses EventSource as primary transport with automatic version-gated polling fallback for restricted environments
  • Includes interactive sandbox test (tests/manual/local/test-external-annotations.sh) that demos all operations: single add, batch add, delete, clear — streaming live to the browser

API

Route Method Purpose
/api/external-annotations/stream GET SSE stream — snapshot on connect, live events
/api/external-annotations GET JSON snapshot with ?since=N version gating (304 when unchanged)
/api/external-annotations POST Add single or batch ({ annotations: [...] }). Returns { ids }
/api/external-annotations DELETE By ?id=, ?source=, or clear all

New files

  • packages/shared/external-annotation.ts — types, store, validation, SSE helpers
  • packages/server/external-annotations.ts — Bun handler
  • apps/pi-extension/server/external-annotations.ts — Pi handler (node:http)
  • packages/ui/hooks/useExternalAnnotations.ts — EventSource + polling fallback
  • packages/ui/components/ExternalAnnotationCard.tsx — card with kind badges, source labels
  • tests/manual/test-external-annotations.ts — sandbox demo script

Coexistence

Existing VS Code editor annotations (/api/editor-annotation) are untouched — both systems run side by side.

Test plan

  • Run ./tests/manual/local/test-external-annotations.sh — watch annotations arrive in real-time over 6 waves
  • Verify SSE reconnection: kill curl stream, reconnect, get fresh snapshot
  • Verify polling fallback: disable EventSource in dev tools, annotations still appear
  • Verify existing /api/editor-annotation endpoints still work
  • bun run build:hook && bun run --cwd apps/review build — clean builds
  • Pi build: bun run --cwd apps/pi-extension buildgenerated/external-annotation.ts created

Add a general-purpose external annotations API that allows any program
to submit annotations to a running Plannotator server and have them
appear in the browser UI in real-time via Server-Sent Events.

Core architecture:
- Shared store logic in packages/shared/external-annotation.ts (runtime-agnostic)
- Bun handler (packages/server/external-annotations.ts) and Pi handler
  (apps/pi-extension/server/external-annotations.ts) are thin HTTP adapters
  over the same shared core, ensuring identical behavior
- SSE stream with 30s heartbeat, version-gated GET polling fallback
- Batch submission support, delete by ID/source/all

Endpoints: POST/GET/DELETE /api/external-annotations, GET /stream

Frontend: useExternalAnnotations hook (EventSource + polling fallback),
ExternalAnnotationCard component with kind badges and source labels,
exportExternalAnnotations grouped by source. Wired into both plan and
review editors alongside existing editor annotations.

For provenance purposes, this commit was AI assisted.
Interactive test script that starts a review server with sample diff
data and sends 6 waves of annotations over ~17 seconds, demonstrating
single add, batch add, delete by ID, and clear by source — all
streaming to the browser in real-time via SSE.

Run: ./tests/manual/local/test-external-annotations.sh

For provenance purposes, this commit was AI assisted.
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