Add AI provider layer with Claude Agent SDK integration#361
Closed
backnotprop wants to merge 1 commit into
Closed
Conversation
Introduces a new packages/ai/ package that provides the backbone for AI-powered features (inline chat, plan Q&A, code review assistance) across all Plannotator surfaces. Architecture: - Abstract AIProvider interface that any agent runtime can implement - First concrete provider: Claude Agent SDK with session forking support - Context builders that translate plan/review/annotate state into prompts - SessionManager for tracking active/forked conversations - HTTP endpoint handlers (SSE streaming) ready to mount in any server - 21 tests covering all layers The provider layer supports forking from parent Claude Code sessions via the Agent SDK's forkSession option, preserving full conversation history so inline questions maintain context. https://claude.ai/code/session_01Dxnd27WsNiz5J42tnyFYfD
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
This PR introduces a complete AI provider abstraction layer for Plannotator, enabling AI-powered features (inline chat, plan Q&A, code review assistance) across all review surfaces. It includes a pluggable provider architecture, the first concrete implementation (Claude Agent SDK), HTTP endpoints for streaming responses, and comprehensive test coverage.
Key Changes
Core Types (
types.ts): Defined abstract interfaces for AI providers, sessions, messages, and context modes (plan-review, code-review, annotate). Supports forking from parent agent sessions to maintain conversation history.Provider Registry (
provider.ts): Implemented a pluggable provider registry with factory pattern support. Allows runtime registration/unregistration of providers and dynamic provider creation from configuration.Session Manager (
session-manager.ts): Built in-memory session tracking with LRU eviction, parent-child session lineage tracking, and metadata for UI display (timestamps, mode, labels).Context Builders (
context.ts): Created system prompt and fork preamble generators that translate Plannotator review state into AI-friendly context. Includes content truncation to respect context windows.HTTP Endpoints (
endpoints.ts): Implemented provider-agnostic REST endpoints:POST /api/ai/session— Create or fork sessionsPOST /api/ai/query— Stream responses via Server-Sent EventsPOST /api/ai/abort— Cancel in-flight queriesGET /api/ai/sessions— List active sessionsGET /api/ai/capabilities— Check provider availabilityClaude Agent SDK Provider (
providers/claude-agent-sdk.ts): First concrete provider implementation supporting:Comprehensive Tests (
ai.test.ts): 407 lines of test coverage including:Notable Implementation Details
Provider-agnostic design: HTTP endpoints and context builders work with any AIProvider implementation, enabling future providers (OpenCode, etc.) without changes to core infrastructure.
Fork semantics: Forked sessions inherit parent conversation history while receiving Plannotator review context, enabling contextual questions like "why did you change this function?"
Streaming architecture: Uses Server-Sent Events (SSE) for real-time response streaming with proper error handling and completion signaling.
Optional peer dependency: Claude Agent SDK is a peer dependency with dynamic import, allowing the package to be used in environments where the SDK isn't installed.
Session lineage tracking: Maintains parent-child relationships for forked sessions, enabling UI features like "show related conversations."
Cost-bounded inline chat: Default configuration limits agentic turns and provides budget controls to keep inline chat fast and cost-effective.