feat: external annotations API with real-time SSE#400
Open
backnotprop wants to merge 2 commits intomainfrom
Open
feat: external annotations API with real-time SSE#400backnotprop wants to merge 2 commits intomainfrom
backnotprop wants to merge 2 commits intomainfrom
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
packages/shared/ensures identical behavior between Bun and Pi servers — both are thin HTTP adapters over the same runtime-agnostic codeEventSourceas primary transport with automatic version-gated polling fallback for restricted environmentstests/manual/local/test-external-annotations.sh) that demos all operations: single add, batch add, delete, clear — streaming live to the browserAPI
/api/external-annotations/stream/api/external-annotations?since=Nversion gating (304 when unchanged)/api/external-annotations{ annotations: [...] }). Returns{ ids }/api/external-annotations?id=,?source=, or clear allNew files
packages/shared/external-annotation.ts— types, store, validation, SSE helperspackages/server/external-annotations.ts— Bun handlerapps/pi-extension/server/external-annotations.ts— Pi handler (node:http)packages/ui/hooks/useExternalAnnotations.ts— EventSource + polling fallbackpackages/ui/components/ExternalAnnotationCard.tsx— card with kind badges, source labelstests/manual/test-external-annotations.ts— sandbox demo scriptCoexistence
Existing VS Code editor annotations (
/api/editor-annotation) are untouched — both systems run side by side.Test plan
./tests/manual/local/test-external-annotations.sh— watch annotations arrive in real-time over 6 waves/api/editor-annotationendpoints still workbun run build:hook && bun run --cwd apps/review build— clean buildsbun run --cwd apps/pi-extension build—generated/external-annotation.tscreated